From 73c1ceaf4280bd0318679c1ad832181f3f449814 Mon Sep 17 00:00:00 2001 From: Dan Hart Date: Sun, 13 Jul 2014 18:53:00 +0100 Subject: [PATCH] Ajax: Fix for request aborted in ajaxSend Fixes gh-1775 Close gh-1619 --- src/ajax.js | 6 ++++++ test/unit/ajax.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ajax.js b/src/ajax.js index 7a0ac1f07..d44a76095 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -644,6 +644,12 @@ jQuery.extend({ if ( fireGlobals ) { globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] ); } + + // If request was aborted inside ajaxSend, stop there + if ( state === 2 ) { + return jqXHR; + } + // Timeout if ( s.async && s.timeout > 0 ) { timeoutTimer = setTimeout(function() { diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 868f19bc8..c63fd69d9 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -435,6 +435,23 @@ module( "ajax", { }; }); + ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, { + setup: function() { + jQuery( document ).on( "ajaxSend", function( e, jqXHR ) { + jqXHR.abort(); + }); + + jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) { + equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" ); + }); + }, + url: url("data/name.html"), + error: true, + complete: function() { + ok( true, "complete" ); + } + }); + ajaxTest( "jQuery.ajax() - context modification", 1, { url: url("data/name.html"), context: {}, -- 2.39.5