aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax.js
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2015-11-15 21:51:18 -0500
committerDave Methvin <dave.methvin@gmail.com>2015-11-30 19:55:50 -0500
commite077ffb083743f4a4b990f586c9d25d787e7b417 (patch)
treefc636e7300a36da6d1c16978c4a355afec54135c /src/ajax.js
parenteaa3e9f0cfc68083556cf61195821d90e369f646 (diff)
downloadjquery-e077ffb083743f4a4b990f586c9d25d787e7b417.tar.gz
jquery-e077ffb083743f4a4b990f586c9d25d787e7b417.zip
Ajax: Preserve URL hash on requests
Fixes gh-1732 Closes gh-2721
Diffstat (limited to 'src/ajax.js')
-rw-r--r--src/ajax.js28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/ajax.js b/src/ajax.js
index 27abe375e..195a30a20 100644
--- a/src/ajax.js
+++ b/src/ajax.js
@@ -415,6 +415,9 @@ jQuery.extend( {
// Loop variable
i,
+ // uncached part of the url
+ uncached,
+
// Create the final options object
s = jQuery.ajaxSetup( {}, options ),
@@ -516,11 +519,10 @@ jQuery.extend( {
// Attach deferreds
deferred.promise( jqXHR );
- // Remove hash character (#7531: and string promotion)
// Add protocol if not provided (prefilters might expect it)
// Handle falsy url in the settings object (#10093: consistency with old signature)
// We also use the url parameter if available
- s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" )
+ s.url = ( ( url || s.url || location.href ) + "" )
.replace( rprotocol, location.protocol + "//" );
// Alias method option to type as per ticket #12004
@@ -581,30 +583,32 @@ jQuery.extend( {
// Save the URL in case we're toying with the If-Modified-Since
// and/or If-None-Match header later on
- cacheURL = s.url;
+ // Remove hash to simplify url manipulation
+ cacheURL = s.url.replace( rhash, "" );
// More options handling for requests with no content
if ( !s.hasContent ) {
+ // Remember the hash so we can put it back
+ uncached = s.url.slice( cacheURL.length );
+
// If data is available, append data to url
if ( s.data ) {
- cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
+ cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data;
// #9682: remove data so that it's not used in an eventual retry
delete s.data;
}
- // Add anti-cache in url if needed
+ // Add anti-cache in uncached url if needed
if ( s.cache === false ) {
- s.url = rts.test( cacheURL ) ?
-
- // If there is already a '_' parameter, set its value
- cacheURL.replace( rts, "$1_=" + nonce++ ) :
-
- // Otherwise add one to the end
- cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
+ cacheURL = cacheURL.replace( rts, "" );
+ uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached;
}
+ // Put hash and anti-cache on the URL that will be requested (gh-1732)
+ s.url = cacheURL + uncached;
+
// Change '%20' to '+' if this is encoded form body content (gh-2658)
} else if ( s.data && s.processData &&
( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) === 0 ) {