Skip to content

Commit 598ed05

Browse files
Dan Harttimmywil
Dan Hart
authored andcommitted
Ajax: Fix for request aborted in ajaxSend
Fixes gh-1775 Close gh-1619
1 parent 31d58c5 commit 598ed05

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ajax.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,12 @@ jQuery.extend({
627627
if ( fireGlobals ) {
628628
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
629629
}
630+
631+
// If request was aborted inside ajaxSend, stop there
632+
if ( state === 2 ) {
633+
return jqXHR;
634+
}
635+
630636
// Timeout
631637
if ( s.async && s.timeout > 0 ) {
632638
timeoutTimer = setTimeout(function() {

test/unit/ajax.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,23 @@ module( "ajax", {
440440
};
441441
});
442442

443+
ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, {
444+
setup: function() {
445+
jQuery( document ).on( "ajaxSend", function( e, jqXHR ) {
446+
jqXHR.abort();
447+
});
448+
449+
jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) {
450+
equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" );
451+
});
452+
},
453+
url: url("data/name.html"),
454+
error: true,
455+
complete: function() {
456+
ok( true, "complete" );
457+
}
458+
});
459+
443460
ajaxTest( "jQuery.ajax() - context modification", 1, {
444461
url: url("data/name.html"),
445462
context: {},

0 commit comments

Comments
 (0)