From ea12c7594080a111e797ff3e703e144610eb0be3 Mon Sep 17 00:00:00 2001 From: scottjehl Date: Wed, 3 Nov 2010 22:00:49 -0400 Subject: [PATCH] Make sure that Ajax form submissions (both get and post) always make a new request, even if it's identical to a previous submission. When a duplicate cached result page is present, it'll be removed from the DOM after the page change is complete . Thanks @medovob for the ideas and feature request. Fixes #368, Fixes #366 --- js/jquery.mobile.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js index 12664f69..6d20446f 100644 --- a/js/jquery.mobile.js +++ b/js/jquery.mobile.js @@ -233,13 +233,16 @@ url = fileUrl = $.type(to) === "string" ? to.replace( /^#/, "" ) : null, data = undefined, type = 'get', + isFormRequest = false, + duplicateCachedPage = null, back = (back !== undefined) ? back : ( urlStack.length > 1 && urlStack[ urlStack.length - 2 ].url === url ), transition = (transition !== undefined) ? transition : ( pageTransition || "slide" ); if( $.type(to) === "object" ){ url = to.url, data = to.data, - type = to.type; + type = to.type, + isFormRequest = true; //make get requests bookmarkable if( data && type == 'get' ){ url += "?" + data; @@ -286,6 +289,11 @@ }, 500); } removeActiveLinkClass(); + + //if there's a duplicateCachedPage, remove it from the DOM now that it's hidden + if( duplicateCachedPage != null ){ + duplicateCachedPage.remove(); + } } if(transition){ @@ -336,13 +344,18 @@ } // find the "to" page, either locally existing in the dom or by creating it through ajax - if ( to.length ) { + if ( to.length && !isFormRequest ) { if( fileUrl ){ setBaseURL(fileUrl); } enhancePage(); transitionPages(); } else { + + //if to exists in DOM, save a reference to it in duplicateCachedPage for removal after page change + if( to.length ){ + duplicateCachedPage = to; + } pageLoading();