]> 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:44:43 +0000 (12:44 -0400)
Fixes gh-1775
Close gh-1619

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

index 400108e1c19e011b6ece30086f8a4fda0bd79a8c..dad2f8282590ccad3c6bd40460ec53a41f981083 100644 (file)
@@ -627,6 +627,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 528d3a496c77096e552c3a474b4b2e0037281a27..d61d6b40d83706d53d6fe3ef8eb2643bf39365e4 100644 (file)
@@ -440,6 +440,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: {},