]> source.dussan.org Git - jquery.git/commitdiff
Makes sure statusCode callbacks are ordered in the same way success and error callbac...
authorjaubourg <j@ubourg.net>
Thu, 20 Jan 2011 14:39:30 +0000 (15:39 +0100)
committerjaubourg <j@ubourg.net>
Thu, 20 Jan 2011 14:39:30 +0000 (15:39 +0100)
src/ajax.js
test/unit/ajax.js

index fc1ecfde373a9fbc4e99e4d5850aeb4a14444572..63914d23a7aa876499b87be16ea6c1ccec1f0a40 100644 (file)
@@ -427,10 +427,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 ) {
@@ -588,6 +586,8 @@ jQuery.extend({
                        }
 
                        // Status-dependent callbacks
+                       oldStatusCode = statusCode;
+                       statusCode = undefined;
                        jXHR.statusCode( oldStatusCode );
 
                        if ( s.global ) {
index d262988eb85afa3f0223ea0200e1982a5af5b062..1ed15b50c84bc04cf7b893827f0b63623903928c 100644 (file)
@@ -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() {