aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2011-01-20 11:58:52 -0500
committerjeresig <jeresig@gmail.com>2011-01-20 11:58:52 -0500
commitea5ce8c2a916ad44af21411d6e2b21ab9f6863f0 (patch)
tree2ded9d177a12adbc917e22cfb056d23e28e4c189
parente4d01688932960896419dc52ffd691cc4f9b3029 (diff)
parentf2b0c77dc84d3019db96de0c060207a5063f2055 (diff)
downloadjquery-ea5ce8c2a916ad44af21411d6e2b21ab9f6863f0.tar.gz
jquery-ea5ce8c2a916ad44af21411d6e2b21ab9f6863f0.zip
Merge branch 'master' of github.com:jquery/jquery
-rw-r--r--src/ajax.js58
-rw-r--r--src/ajax/xhr.js23
-rw-r--r--src/core.js14
-rw-r--r--test/unit/ajax.js33
-rw-r--r--test/unit/core.js2
5 files changed, 78 insertions, 52 deletions
diff --git a/src/ajax.js b/src/ajax.js
index fc1ecfde3..a92522f5b 100644
--- a/src/ajax.js
+++ b/src/ajax.js
@@ -235,7 +235,7 @@ jQuery.extend({
// Utility function that handles dataType when response is received
// (for those transports that can give text or xml responses)
- determineDataType: function( ct , text , xml ) {
+ determineResponse: function( responses , ct ) {
var s = this,
contents = s.contents,
@@ -246,7 +246,7 @@ jQuery.extend({
response;
// Auto (xml, json, script or text determined given headers)
- if ( transportDataType === "*" ) {
+ if ( ct && transportDataType === "*" ) {
for ( type in contents ) {
if ( ( regexp = contents[ type ] ) && regexp.test( ct ) ) {
@@ -256,23 +256,22 @@ jQuery.extend({
}
}
- // xml and parsed as such
- if ( transportDataType === "xml" &&
- xml &&
- xml.documentElement /* #4958 */ ) {
-
- response = xml;
-
- // Text response was provided
- } else {
+ // Get response
+ for( type in responses ) {
+ if ( type === transportDataType ) {
+ break;
+ }
+ }
- response = text;
+ // Get final response
+ response = responses[ type ];
- // If it's not really text, defer to converters
- if ( transportDataType !== "text" ) {
- dataTypes.unshift( "text" );
+ // If it's not the right dataType, handle the dataTypeList
+ if ( transportDataType !== type ) {
+ if ( transportDataType === "*" ) {
+ dataTypes.shift();
}
-
+ dataTypes.unshift( type );
}
return response;
@@ -291,18 +290,16 @@ jQuery.extend({
// Main method
ajax: function( url , options ) {
- // Handle varargs
- if ( arguments.length === 1 ) {
+ // If options is not an object,
+ // we simulate pre-1.5 signature
+ if ( typeof( options ) !== "object" ) {
options = url;
- url = options ? options.url : undefined;
+ url = undefined;
}
// Force options to be an object
options = options || {};
- // Get the url if provided separately
- options.url = url || options.url;
-
var // Create the final options object
s = jQuery.extend( true , {} , jQuery.ajaxSettings , options ),
// jQuery lists
@@ -427,10 +424,8 @@ jQuery.extend({
// Stored error
error,
- // Keep track of statusCode callbacks
- oldStatusCode = statusCode;
-
- statusCode = undefined;
+ // To keep track of statusCode based callbacks
+ oldStatusCode;
// If successful, handle type chaining
if ( status >= 200 && status < 300 || status === 304 ) {
@@ -582,12 +577,14 @@ jQuery.extend({
// Success/Error
if ( isSuccess ) {
- deferred.fire( callbackContext , [ success , statusText , jXHR ] );
+ deferred.resolveWith( callbackContext , [ success , statusText , jXHR ] );
} else {
- deferred.fireReject( callbackContext , [ jXHR , statusText , error ] );
+ deferred.rejectWith( callbackContext , [ jXHR , statusText , error ] );
}
// Status-dependent callbacks
+ oldStatusCode = statusCode;
+ statusCode = undefined;
jXHR.statusCode( oldStatusCode );
if ( s.global ) {
@@ -596,7 +593,7 @@ jQuery.extend({
}
// Complete
- completeDeferred.fire( callbackContext, [ jXHR , statusText ] );
+ completeDeferred.resolveWith( callbackContext, [ jXHR , statusText ] );
if ( s.global ) {
globalEventContext.trigger( "ajaxComplete" , [ jXHR , s] );
@@ -630,7 +627,8 @@ jQuery.extend({
};
// Remove hash character (#7531: and string promotion)
- s.url = ( "" + s.url ).replace( rhash , "" );
+ // We also use the url parameter if available
+ s.url = ( "" + ( url || s.url ) ).replace( rhash , "" );
// Extract dataTypes list
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( /\s+/ );
diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js
index 4acb70054..cd9838c3b 100644
--- a/src/ajax/xhr.js
+++ b/src/ajax/xhr.js
@@ -12,8 +12,8 @@ var // Next active xhr id
// XHR used to determine supports properties
testXHR;
-// Create the request object; Microsoft failed to properly
-// (This is still attached to ajaxSettings for backward compatibility reasons)
+// Create the request object
+// (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xhr = window.ActiveXObject ?
/* Microsoft failed to properly
* implement the XMLHttpRequest in IE7 (can't request local files),
@@ -146,8 +146,9 @@ if ( jQuery.support.ajax ) {
// Get info
var status = xhr.status,
statusText,
- response,
- responseHeaders = xhr.getAllResponseHeaders();
+ responseHeaders = xhr.getAllResponseHeaders(),
+ responses = {},
+ xml = xhr.responseXML;
try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests
@@ -184,15 +185,15 @@ if ( jQuery.support.ajax ) {
status
);
- // Guess response & update dataType accordingly
- response =
- s.determineDataType(
- xhr.getResponseHeader("content-type"),
- xhr.responseText,
- xhr.responseXML );
+ // Construct response list
+ if ( xml && xml.documentElement /* #4958 */ ) {
+ responses.xml = xml;
+ }
+ responses.text = xhr.responseText;
// Call complete
- complete(status,statusText,response,responseHeaders);
+ complete(status,statusText,s.determineResponse( responses,
+ xhr.getResponseHeader( "content-type" ) ),responseHeaders);
}
}
};
diff --git a/src/core.js b/src/core.js
index 6d333c59e..236f84d88 100644
--- a/src/core.js
+++ b/src/core.js
@@ -399,7 +399,7 @@ jQuery.extend({
}
// If there are functions bound, to execute
- readyList.fire( document , [ jQuery ] );
+ readyList.resolveWith( document , [ jQuery ] );
// Trigger any bound ready events
if ( jQuery.fn.trigger ) {
@@ -837,7 +837,7 @@ jQuery.extend({
}
if ( _fired ) {
- deferred.fire( _fired[ 0 ] , _fired[ 1 ] );
+ deferred.resolveWith( _fired[ 0 ] , _fired[ 1 ] );
}
}
@@ -845,7 +845,7 @@ jQuery.extend({
},
// resolve with given context and args
- fire: function( context , args ) {
+ resolveWith: function( context , args ) {
if ( ! cancelled && ! fired && ! firing ) {
firing = 1;
@@ -865,7 +865,7 @@ jQuery.extend({
// resolve with this as context and given arguments
resolve: function() {
- deferred.fire( jQuery.isFunction( this.promise ) ? this.promise() : this , arguments );
+ deferred.resolveWith( jQuery.isFunction( this.promise ) ? this.promise() : this , arguments );
return this;
},
@@ -901,7 +901,7 @@ jQuery.extend({
return this;
},
fail: failDeferred.done,
- fireReject: failDeferred.fire,
+ rejectWith: failDeferred.resolveWith,
reject: failDeferred.resolve,
isRejected: failDeferred.isResolved,
// Get a promise for this deferred
@@ -954,10 +954,10 @@ jQuery.extend({
args = arguments;
resolveArray[ index ] = args.length > 1 ? slice.call( args , 0 ) : value;
if( ! --length ) {
- deferred.fire( promise, resolveArray );
+ deferred.resolveWith( promise, resolveArray );
}
}).fail( function() {
- deferred.fireReject( promise, arguments );
+ deferred.rejectWith( promise, arguments );
});
return !deferred.isRejected();
});
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index d262988eb..1ed15b50c 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1911,9 +1911,9 @@ test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
test( "jQuery.ajax - statusCode" , function() {
- var count = 10;
+ var count = 12;
- expect( 16 );
+ expect( 20 );
stop();
function countComplete() {
@@ -1975,8 +1975,35 @@ test( "jQuery.ajax - statusCode" , function() {
}
}).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) );
- });
+ var testString = "";
+
+ jQuery.ajax( url( uri ), {
+ success: function( a , b , jXHR ) {
+ ok( isSuccess , "success" );
+ var statusCode = {};
+ statusCode[ jXHR.status ] = function() {
+ testString += "B";
+ };
+ jXHR.statusCode( statusCode );
+ testString += "A";
+ },
+ error: function( jXHR ) {
+ ok( ! isSuccess , "error" );
+ var statusCode = {};
+ statusCode[ jXHR.status ] = function() {
+ testString += "B";
+ };
+ jXHR.statusCode( statusCode );
+ testString += "A";
+ },
+ complete: function() {
+ strictEqual( testString , "AB" , "Test statusCode callbacks are ordered like " +
+ ( isSuccess ? "success" : "error" ) + " callbacks" );
+ countComplete();
+ }
+ } );
+ });
});
test("jQuery.ajax - active counter", function() {
diff --git a/test/unit/core.js b/test/unit/core.js
index 8e57edf95..30039bf92 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1002,7 +1002,7 @@ test("jQuery._Deferred()", function() {
deferred = jQuery._Deferred();
- deferred.fire( jQuery , [ document ] ).done( function( doc ) {
+ deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
});
});