Skip to main content

Bug Tracker

Side navigation

#14011 closed bug (notabug)

Opened June 12, 2013 01:48AM UTC

Closed June 23, 2013 03:39PM UTC

done/fail/always callbacks not called for HTTP status code 202

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.2
Keywords: Cc:
Blocked by: Blocking:

My server returns status code 202 upon successful DELETE request. My client code makes a jQuery AJAX call to issue DELETE request. I tried all combinations of including done/fail/always and success/error/complete callbacks. I see that done/fail/always callbacks are never called, but success/error/complete are called. I also included a callback for statusCode 202, and I see that was called AFTER the success callback was called.

Since success/error/complete callbacks are deprecated, it seems to me that done/fail/always callbacks should be executed in this scenario instead.

The documentation at also does not document when statusCode callback will be invoked.

Attachments (0)
Change History (4)

Changed June 12, 2013 04:06AM UTC by jaubourg comment:1

A jsfiddle example would help a lot but my guess is you're using done/fail/always like options:

$.ajax( {
    done: myDoneCallback
} );

But done/fail/always aren't options, they're methods of the returned jqXHR object:

$.ajax().done( myDoneCallback );

The success/error/complete that are deprecated are the *methods* too, not the options.

// Deprecated
$.ajax().success( myDoneCallback );

// Not Deprecated
$.ajax( {
    success: myDoneCallback
} );

Regarding statusCode, the documentation states:

An object of numeric HTTP codes and functions to be called when the response has the corresponding code. For example, the following will alert when the response status is a 404:
>        $.ajax({
>          statusCode: {
>            404: function() {
>              alert("page not found");
>            }
>          }
>        });
If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error (including 3xx redirect), they take the same parameters as the error callback.

So a statusCode callback will always be called regardless of the success/error status of the ajax call. Exact, relative timing, isn't given nor should it (because you shouldn't rely on it) but callbacks are called in the order they are added. For options callbacks, I don't remember which comes first though between complete and statusCode callbacks but success/error will be called prior to anything else.

For exact ordering, use the methods.

// Provided the request is successful
$.ajax().done( callNumber1 ).statusCode( {
    202: callNumber2
} ).always( callNumber3 ).statusCode( {
    202: callNumber4
} ).done( callNumber5 );

Changed June 12, 2013 04:07AM UTC by jaubourg comment:2

#14012 is a duplicate of this ticket.

Changed June 12, 2013 07:35PM UTC by anonymous comment:3

Thank you, this addresses my issue. If you could include some or all of this information in the documentation, that would be helpful.

Changed June 23, 2013 03:39PM UTC by dmethvin comment:4

resolution: → notabug
status: newclosed

The docs seem clear enough, further clarification can be had by asking targeted questions on our forum or StackOverflow. Making the ajax docs longer to clarify obscure points will make it harder to understand.