From: jaubourg Date: Mon, 2 Apr 2012 00:04:46 +0000 (+0200) Subject: For much improved consistency, jqXHR.abort() sets a default statusText of 'canceled... X-Git-Tag: 1.8b1~230 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=914df9cb42219200a0286d15e0f45a9994b8ab3d;p=jquery.git For much improved consistency, jqXHR.abort() sets a default statusText of 'canceled' right until after beforeSend has been called (in which case it reverts to the default of 'abort'): now all early aborts have a statusText of 'canceled'. --- diff --git a/src/ajax.js b/src/ajax.js index ca9b63322..9aa715cd2 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -426,6 +426,8 @@ jQuery.extend({ fireGlobals, // Loop variable i, + // Default abort message + strAbort = "canceled", // Fake xhr jqXHR = { @@ -471,7 +473,7 @@ jQuery.extend({ // Cancel the request abort: function( statusText ) { - statusText = statusText || "abort"; + statusText = statusText || strAbort; if ( transport ) { transport.abort( statusText ); } @@ -716,12 +718,14 @@ jQuery.extend({ // Allow custom headers/mimetypes and early abort if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) { - // Abort if not done already - done( 0, "canceled" ); - return jqXHR; + // Abort if not done already and return + return jqXHR.abort(); } + // aborting is no longer a cancelation + strAbort = "abort"; + // Install callbacks on deferreds for ( i in { success: 1, error: 1, complete: 1 } ) { jqXHR[ i ]( s[ i ] ); diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 431f14094..963bcae7a 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -895,7 +895,7 @@ test("jQuery.ajax - beforeSend, cancel request manually", function() { ok( false, "request didn't get canceled" ); } }).fail(function( _, reason ) { - strictEqual( reason, "abort", "manually canceled request must fail with 'abort' status text" ); + strictEqual( reason, "canceled", "manually canceled request must fail with 'canceled' status text" ); }); }); @@ -2324,7 +2324,7 @@ test("jQuery.ajax - abort in prefilter", function() { ok( false, "error callback called" ); } }).fail(function( _, reason ) { - strictEqual( reason, 'abort', "Request aborted by the prefilter must fail with 'abort' status text" ); + strictEqual( reason, 'canceled', "Request aborted by the prefilter must fail with 'canceled' status text" ); }); });