git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixes #7945. Make jQuery.param() serialize plain objects with a property named jquery...
[jquery.git]
/
src
/
ajax.js
diff --git
a/src/ajax.js
b/src/ajax.js
index
11eacee
..
1a19d0c
100644
(file)
--- a/
src/ajax.js
+++ b/
src/ajax.js
@@
-73,7
+73,7
@@
function addToPrefiltersOrTransports( structure ) {
}
//Base inspection function for prefilters and transports
}
//Base inspection function for prefilters and transports
-function inspectPrefiltersOrTransports( structure, options, originalOptions, jXHR,
+function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR,
dataType /* internal */, inspected /* internal */ ) {
dataType = dataType || options.dataTypes[ 0 ];
dataType /* internal */, inspected /* internal */ ) {
dataType = dataType || options.dataTypes[ 0 ];
@@
-88,7
+88,7
@@
function inspectPrefiltersOrTransports( structure, options, originalOptions, jXH
selection;
for(; i < length && ( executeOnly || !selection ); i++ ) {
selection;
for(; i < length && ( executeOnly || !selection ); i++ ) {
- selection = list[ i ]( options, originalOptions, jXHR );
+ selection = list[ i ]( options, originalOptions, jqXHR );
// If we got redirected to another dataType
// we try there if not done already
if ( typeof selection === "string" ) {
// If we got redirected to another dataType
// we try there if not done already
if ( typeof selection === "string" ) {
@@
-97,7
+97,7
@@
function inspectPrefiltersOrTransports( structure, options, originalOptions, jXH
} else {
options.dataTypes.unshift( selection );
selection = inspectPrefiltersOrTransports(
} else {
options.dataTypes.unshift( selection );
selection = inspectPrefiltersOrTransports(
- structure, options, originalOptions, jXHR, selection, inspected );
+ structure, options, originalOptions, jqXHR, selection, inspected );
}
}
}
}
}
}
@@
-105,7
+105,7
@@
function inspectPrefiltersOrTransports( structure, options, originalOptions, jXH
// we try the catchall dataType if not done already
if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) {
selection = inspectPrefiltersOrTransports(
// we try the catchall dataType if not done already
if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) {
selection = inspectPrefiltersOrTransports(
- structure, options, originalOptions, jXHR, "*", inspected );
+ structure, options, originalOptions, jqXHR, "*", inspected );
}
// unnecessary when only executing (prefilters)
// but it'll be ignored by the caller in that case
}
// unnecessary when only executing (prefilters)
// but it'll be ignored by the caller in that case
@@
-155,14
+155,14
@@
jQuery.fn.extend({
dataType: "html",
data: params,
// Complete callback (responseText is used internally)
dataType: "html",
data: params,
// Complete callback (responseText is used internally)
- complete: function( jXHR, status, responseText ) {
- // Store the response as specified by the jXHR object
- responseText = jXHR.responseText;
+ complete: function( jqXHR, status, responseText ) {
+ // Store the response as specified by the jqXHR object
+ responseText = jqXHR.responseText;
// If successful, inject the HTML into all the matched elements
// If successful, inject the HTML into all the matched elements
- if ( jXHR.isResolved() ) {
+ if ( jqXHR.isResolved() ) {
// #4825: Get the actual response in case
// a dataFilter is present in ajaxSettings
// #4825: Get the actual response in case
// a dataFilter is present in ajaxSettings
- jXHR.done(function( r ) {
+ jqXHR.done(function( r ) {
responseText = r;
});
// See if a selector was specified
responseText = r;
});
// See if a selector was specified
@@
-181,7
+181,7
@@
jQuery.fn.extend({
}
if ( callback ) {
}
if ( callback ) {
- self.each( callback, [ responseText, status, jXHR ] );
+ self.each( callback, [ responseText, status, jqXHR ] );
}
}
});
}
}
});
@@
-322,9
+322,8
@@
jQuery.extend({
// Main method
ajax: function( url, options ) {
// Main method
ajax: function( url, options ) {
- // If options is not an object,
- // we simulate pre-1.5 signature
- if ( typeof options !== "object" ) {
+ // If url is an object, simulate pre-1.5 signature
+ if ( typeof url === "object" ) {
options = url;
url = undefined;
}
options = url;
url = undefined;
}
@@
-350,6
+349,8
@@
jQuery.extend({
completeDeferred = jQuery._Deferred(),
// Status-dependent callbacks
statusCode = s.statusCode || {},
completeDeferred = jQuery._Deferred(),
// Status-dependent callbacks
statusCode = s.statusCode || {},
+ // ifModified key
+ ifModifiedKey,
// Headers (they are sent all at once)
requestHeaders = {},
// Response headers
// Headers (they are sent all at once)
requestHeaders = {},
// Response headers
@@
-363,12
+364,12
@@
jQuery.extend({
loc = document.location,
protocol = loc.protocol || "http:",
parts,
loc = document.location,
protocol = loc.protocol || "http:",
parts,
- // The jXHR state
+ // The jqXHR state
state = 0,
// Loop variable
i,
// Fake xhr
state = 0,
// Loop variable
i,
// Fake xhr
- jXHR = {
+ jqXHR = {
readyState: 0,
readyState: 0,
@@
-430,19
+431,19
@@
jQuery.extend({
}
// Dereference transport for early garbage collection
}
// Dereference transport for early garbage collection
- // (no matter how long the jXHR object will be used)
+ // (no matter how long the jqXHR object will be used)
transport = undefined;
// Cache response headers
responseHeadersString = headers || "";
// Set readyState
transport = undefined;
// Cache response headers
responseHeadersString = headers || "";
// Set readyState
- jXHR.readyState = status ? 4 : 0;
+ jqXHR.readyState = status ? 4 : 0;
var isSuccess,
success,
error,
var isSuccess,
success,
error,
- response = responses ? ajaxHandleResponses( s, jXHR, responses ) : undefined,
+ response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
lastModified,
etag;
lastModified,
etag;
@@
-452,11
+453,11
@@
jQuery.extend({
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
- if ( ( lastModified = jXHR.getResponseHeader( "Last-Modified" ) ) ) {
- jQuery.lastModified[ s.url ] = lastModified;
+ if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
+ jQuery.lastModified[ ifModifiedKey ] = lastModified;
}
}
- if ( ( etag = jXHR.getResponseHeader( "Etag" ) ) ) {
- jQuery.etag[ s.url ] = etag;
+ if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
+ jQuery.etag[ ifModifiedKey ] = etag;
}
}
}
}
@@
-492,30
+493,30
@@
jQuery.extend({
}
// Set data for the fake xhr object
}
// Set data for the fake xhr object
- jXHR.status = status;
- jXHR.statusText = statusText;
+ jqXHR.status = status;
+ jqXHR.statusText = statusText;
// Success/Error
if ( isSuccess ) {
// Success/Error
if ( isSuccess ) {
- deferred.resolveWith( callbackContext, [ success, statusText, jXHR ] );
+ deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
} else {
} else {
- deferred.rejectWith( callbackContext, [ jXHR, statusText, error ] );
+ deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
}
// Status-dependent callbacks
}
// Status-dependent callbacks
- jXHR.statusCode( statusCode );
+ jqXHR.statusCode( statusCode );
statusCode = undefined;
if ( s.global ) {
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
statusCode = undefined;
if ( s.global ) {
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
- [ jXHR, s, isSuccess ? success : error ] );
+ [ jqXHR, s, isSuccess ? success : error ] );
}
// Complete
}
// Complete
- completeDeferred.resolveWith( callbackContext, [ jXHR, statusText ] );
+ completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] );
if ( s.global ) {
if ( s.global ) {
- globalEventContext.trigger( "ajaxComplete", [ jXHR, s] );
+ globalEventContext.trigger( "ajaxComplete", [ jqXHR, s] );
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
jQuery.event.trigger( "ajaxStop" );
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
jQuery.event.trigger( "ajaxStop" );
@@
-524,13
+525,13
@@
jQuery.extend({
}
// Attach deferreds
}
// Attach deferreds
- deferred.promise( jXHR );
- jXHR.success = jXHR.done;
- jXHR.error = jXHR.fail;
- jXHR.complete = completeDeferred.done;
+ deferred.promise( jqXHR );
+ jqXHR.success = jqXHR.done;
+ jqXHR.error = jqXHR.fail;
+ jqXHR.complete = completeDeferred.done;
// Status-dependent callbacks
// Status-dependent callbacks
- jXHR.statusCode = function( map ) {
+ jqXHR.statusCode = function( map ) {
if ( map ) {
var tmp;
if ( state < 2 ) {
if ( map ) {
var tmp;
if ( state < 2 ) {
@@
-538,8
+539,8
@@
jQuery.extend({
statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ];
}
} else {
statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ];
}
} else {
- tmp = map[ jXHR.status ];
- jXHR.then( tmp, tmp );
+ tmp = map[ jqXHR.status ];
+ jqXHR.then( tmp, tmp );
}
}
return this;
}
}
return this;
@@
-569,7
+570,7
@@
jQuery.extend({
}
// Apply prefilters
}
// Apply prefilters
- inspectPrefiltersOrTransports( prefilters, s, options, jXHR );
+ inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
// Uppercase the type
s.type = s.type.toUpperCase();
// Uppercase the type
s.type = s.type.toUpperCase();
@@
-590,6
+591,9
@@
jQuery.extend({
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
}
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
}
+ // Get ifModifiedKey before adding the anti-cache parameter
+ ifModifiedKey = s.url;
+
// Add anti-cache in url if needed
if ( s.cache === false ) {
// Add anti-cache in url if needed
if ( s.cache === false ) {
@@
-609,11
+613,12
@@
jQuery.extend({
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
- if ( jQuery.lastModified[ s.url ] ) {
- requestHeaders[ "if-modified-since" ] = jQuery.lastModified[ s.url ];
+ ifModifiedKey = ifModifiedKey || s.url;
+ if ( jQuery.lastModified[ ifModifiedKey ] ) {
+ requestHeaders[ "if-modified-since" ] = jQuery.lastModified[ ifModifiedKey ];
}
}
- if ( jQuery.etag[ s.url ] ) {
- requestHeaders[ "if-none-match" ] = jQuery.etag[ s.url ];
+ if ( jQuery.etag[ ifModifiedKey ] ) {
+ requestHeaders[ "if-none-match" ] = jQuery.etag[ ifModifiedKey ];
}
}
}
}
@@
-628,36
+633,36
@@
jQuery.extend({
}
// Allow custom headers/mimetypes and early abort
}
// Allow custom headers/mimetypes and early abort
- if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jXHR, s ) === false || state === 2 ) ) {
+ if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
// Abort if not done already
done( 0, "abort" );
// Return false
// Abort if not done already
done( 0, "abort" );
// Return false
- jXHR = false;
+ jqXHR = false;
} else {
// Install callbacks on deferreds
for ( i in { success: 1, error: 1, complete: 1 } ) {
} else {
// Install callbacks on deferreds
for ( i in { success: 1, error: 1, complete: 1 } ) {
- jXHR[ i ]( s[ i ] );
+ jqXHR[ i ]( s[ i ] );
}
// Get transport
}
// Get transport
- transport = inspectPrefiltersOrTransports( transports, s, options, jXHR );
+ transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
// If no transport, we auto-abort
if ( !transport ) {
done( -1, "No Transport" );
} else {
// Set state as sending
// If no transport, we auto-abort
if ( !transport ) {
done( -1, "No Transport" );
} else {
// Set state as sending
- state = jXHR.readyState = 1;
+ state = jqXHR.readyState = 1;
// Send global event
if ( s.global ) {
// Send global event
if ( s.global ) {
- globalEventContext.trigger( "ajaxSend", [ jXHR, s ] );
+ globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
}
// Timeout
if ( s.async && s.timeout > 0 ) {
timeoutTimer = setTimeout( function(){
}
// Timeout
if ( s.async && s.timeout > 0 ) {
timeoutTimer = setTimeout( function(){
- jXHR.abort( "timeout" );
+ jqXHR.abort( "timeout" );
}, s.timeout );
}
}, s.timeout );
}
@@
-674,7
+679,7
@@
jQuery.extend({
}
}
}
}
}
}
- return jXHR;
+ return jqXHR;
},
// Serialize an array of form elements or a set of
},
// Serialize an array of form elements or a set of
@@
-693,7
+698,7
@@
jQuery.extend({
}
// If an array was passed in, assume that it is an array of form elements.
}
// If an array was passed in, assume that it is an array of form elements.
- if ( jQuery.isArray( a ) || a.jquery ) {
+ if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
// Serialize the form elements
jQuery.each( a, function() {
add( this.name, this.value );
// Serialize the form elements
jQuery.each( a, function() {
add( this.name, this.value );
@@
-769,7
+774,7
@@
jQuery.extend({
* - finds the right dataType (mediates between content-type and expected dataType)
* - returns the corresponding response
*/
* - finds the right dataType (mediates between content-type and expected dataType)
* - returns the corresponding response
*/
-function ajaxHandleResponses( s, jXHR, responses ) {
+function ajaxHandleResponses( s, jqXHR, responses ) {
var contents = s.contents,
dataTypes = s.dataTypes,
var contents = s.contents,
dataTypes = s.dataTypes,
@@
-782,7
+787,7
@@
function ajaxHandleResponses( s, jXHR, responses ) {
// Fill responseXXX fields
for( type in responseFields ) {
if ( type in responses ) {
// Fill responseXXX fields
for( type in responseFields ) {
if ( type in responses ) {
- jXHR[ responseFields[type] ] = responses[ type ];
+ jqXHR[ responseFields[type] ] = responses[ type ];
}
}
}
}
@@
-790,7
+795,7
@@
function ajaxHandleResponses( s, jXHR, responses ) {
while( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
while( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
- ct = jXHR.getResponseHeader( "content-type" );
+ ct = jqXHR.getResponseHeader( "content-type" );
}
}
}
}
@@
-842,8
+847,9
@@
function ajaxConvert( s, response ) {
}
var dataTypes = s.dataTypes,
}
var dataTypes = s.dataTypes,
- converters = s.converters,
+ converters = {},
i,
i,
+ key,
length = dataTypes.length,
tmp,
// Current and previous dataTypes
length = dataTypes.length,
tmp,
// Current and previous dataTypes
@@
-860,6
+866,16
@@
function ajaxConvert( s, response ) {
// For each dataType in the chain
for( i = 1; i < length; i++ ) {
// For each dataType in the chain
for( i = 1; i < length; i++ ) {
+ // Create converters map
+ // with lowercased keys
+ if ( i === 1 ) {
+ for( key in s.converters ) {
+ if( typeof key === "string" ) {
+ converters[ key.toLowerCase() ] = s.converters[ key ];
+ }
+ }
+ }
+
// Get the dataTypes
prev = current;
current = dataTypes[ i ];
// Get the dataTypes
prev = current;
current = dataTypes[ i ];