Commit 914df9cb authored by jaubourg's avatar jaubourg

For much improved consistency, jqXHR.abort() sets a default statusText of...

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'.
parent 395612bb
...@@ -426,6 +426,8 @@ jQuery.extend({ ...@@ -426,6 +426,8 @@ jQuery.extend({
fireGlobals, fireGlobals,
// Loop variable // Loop variable
i, i,
// Default abort message
strAbort = "canceled",
// Fake xhr // Fake xhr
jqXHR = { jqXHR = {
...@@ -471,7 +473,7 @@ jQuery.extend({ ...@@ -471,7 +473,7 @@ jQuery.extend({
// Cancel the request // Cancel the request
abort: function( statusText ) { abort: function( statusText ) {
statusText = statusText || "abort"; statusText = statusText || strAbort;
if ( transport ) { if ( transport ) {
transport.abort( statusText ); transport.abort( statusText );
} }
...@@ -716,12 +718,14 @@ jQuery.extend({ ...@@ -716,12 +718,14 @@ jQuery.extend({
// Allow custom headers/mimetypes and early abort // Allow custom headers/mimetypes and early abort
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) { if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
// Abort if not done already // Abort if not done already and return
done( 0, "canceled" ); return jqXHR.abort();
return jqXHR;
} }
// aborting is no longer a cancelation
strAbort = "abort";
// Install callbacks on deferreds // Install callbacks on deferreds
for ( i in { success: 1, error: 1, complete: 1 } ) { for ( i in { success: 1, error: 1, complete: 1 } ) {
jqXHR[ i ]( s[ i ] ); jqXHR[ i ]( s[ i ] );
......
...@@ -895,7 +895,7 @@ test("jQuery.ajax - beforeSend, cancel request manually", function() { ...@@ -895,7 +895,7 @@ test("jQuery.ajax - beforeSend, cancel request manually", function() {
ok( false, "request didn't get canceled" ); ok( false, "request didn't get canceled" );
} }
}).fail(function( _, reason ) { }).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() { ...@@ -2324,7 +2324,7 @@ test("jQuery.ajax - abort in prefilter", function() {
ok( false, "error callback called" ); ok( false, "error callback called" );
} }
}).fail(function( _, reason ) { }).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" );
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment