Question

If you execute this code in 1.7, the alert appears and 1.8 it does not:

$.when(
$.ajax({
    url: "whatever",
    dataType: "json",
    beforeSend: function(jqXHR, settings) {
        return false;
    }
})).done(function(a1) {
    alert("this appears in 1.7 but not in 1.8!");
});​

I was unable to find anything in the jQuery documentation, the 1.8 release notes, or the jQuery bug tracker that mentions this issue. I'm wondering which behavior is correct and whether someone can provide a link to a bug ticket or Github commit.

Here is a fiddle for this issue:

http://jsfiddle.net/zJddg/

Was it helpful?

Solution

The alert should not appear. http://api.jquery.com/jQuery.ajax/ says:

In particular, calling .abort() on the object will halt the request before it completes.

And in the code:

    // Allow custom headers/mimetypes and early abort
    if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
            // Abort if not done already and return
            return jqXHR.abort();

    }

I believe this was in response to bug #8193 and possibly bug #10944.

OTHER TIPS

From the jQuery documentation:

Returning false in the beforeSend function will cancel the request.

The current behavior you are experiencing in 1.8 is the expected behavior, if it wasn't canceling the request in 1.7, that would be a bug.

http://api.jquery.com/jQuery.ajax/

I don't see a bug linked in any of the releases that point to fixing this "bug" though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top