]> source.dussan.org Git - jquery.git/commitdiff
Ajax: Fix for request aborted in ajaxSend
authorDan Hart <danhart@notonthehighstreet.com>
Sun, 13 Jul 2014 17:53:00 +0000 (18:53 +0100)
committerTimmy Willison <timmywillisn@gmail.com>
Sat, 1 Nov 2014 16:48:12 +0000 (12:48 -0400)
Fixes gh-1775
Close gh-1619

src/ajax.js
test/unit/ajax.js

index 7a0ac1f07f057df5fd2bcc62667559491f6a42a5..d44a76095accb1d6eaa55875f4b5b915cf836aff 100644 (file)
@@ -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() {
index 868f19bc824a170d5eacc5dd9cf224c7e898989c..c63fd69d935b13c4c6688153af7447170ed32abc 100644 (file)
@@ -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: {},