]> source.dussan.org Git - jquery.git/commitdiff
jquery.ajax: improvement for #2688, added test
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 22 Apr 2008 22:07:17 +0000 (22:07 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 22 Apr 2008 22:07:17 +0000 (22:07 +0000)
src/ajax.js
test/unit/ajax.js

index 77537e7060ab4f291202ee8662473adbbbdf654c..4b84538df33345549d6bc3332ed77c6931f9e200 100644 (file)
@@ -291,11 +291,8 @@ jQuery.extend({
                } catch(e){}
 
                // Allow custom headers/mimetypes
-               if ( s.beforeSend )
-                       var beforeSendSuccess = s.beforeSend(xml, s);
-                       
-               if( beforeSendSuccess === false )
-                 return false;
+               if ( s.beforeSend && s.beforeSend(xml, s) === false )
+                       return false;
                
                if ( s.global )
                        jQuery.event.trigger("ajaxSend", [xml, s]);
index 15c4ed744e44621dde53623e00919e251e6147d6..c6557f4edc77e276bd8e5caaea0f429edeceb4e6 100644 (file)
@@ -136,6 +136,27 @@ test("$.ajax - beforeSend", function() {
        });
 });
 
+test("$.ajax - beforeSend, cancel request (#2688)", function() {
+       expect(2);
+       var request = $.ajax({
+               url: url("data/name.html"), 
+               beforeSend: function() {
+                       ok( true, "beforeSend got called, canceling" );
+                       return false;
+               },
+               success: function() {
+                       ok( false, "request didn't get canceled" );
+               },
+               complete: function() {
+                       ok( false, "request didn't get canceled" );
+               },
+               error: function() {
+                       ok( false, "request didn't get canceled" );
+               }
+       });
+       ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
+});
+
 var foobar;
 
 test("$.ajax - dataType html", function() {