diff --git a/src/ajax.js b/src/ajax.js index 77537e706..4b84538df 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -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]); diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 15c4ed744..c6557f4ed 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -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() {