Skip to content

Commit 73c1cea

Browse files
Dan Harttimmywil
authored andcommitted
Ajax: Fix for request aborted in ajaxSend
Fixes gh-1775 Close gh-1619
1 parent 2a3018c commit 73c1cea

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
@@ -644,6 +644,12 @@ jQuery.extend({
644644
if ( fireGlobals ) {
645645
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
646646
}
647+
648+
// If request was aborted inside ajaxSend, stop there
649+
if ( state === 2 ) {
650+
return jqXHR;
651+
}
652+
647653
// Timeout
648654
if ( s.async && s.timeout > 0 ) {
649655
timeoutTimer = setTimeout(function() {

test/unit/ajax.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,23 @@ module( "ajax", {
435435
};
436436
});
437437

438+
ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, {
439+
setup: function() {
440+
jQuery( document ).on( "ajaxSend", function( e, jqXHR ) {
441+
jqXHR.abort();
442+
});
443+
444+
jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) {
445+
equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" );
446+
});
447+
},
448+
url: url("data/name.html"),
449+
error: true,
450+
complete: function() {
451+
ok( true, "complete" );
452+
}
453+
});
454+
438455
ajaxTest( "jQuery.ajax() - context modification", 1, {
439456
url: url("data/name.html"),
440457
context: {},

0 commit comments

Comments
 (0)