Bug Tracker

Opened 10 years ago

Closed 10 years ago

#12551 closed bug (notabug)

jQuery.ajax 2xx statusCode callbacks are invoked with error-callback parameters when parsererror is raised

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:


Given an ajax request with json dataType and a 2xx statusCode callback, if a parsererror occurs during handling then the parameters passed to the 2xx callback are incorrect. According to the documentation, 2xx handlers receive the same parameters as the success callback. However, after a parsererror, the success callback is treated as an error callback (the parameters received match the function signature for error callbacks).

Change History (2)

comment:1 Changed 10 years ago by gibson042

Owner: set to [email protected]
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 10 years ago by jaubourg

Resolution: notabug
Status: pendingclosed

From the documentation:

If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error, they take the same parameters as the error callback.

Not being able to parse the response is an error and statusCode callbacks are called no matter what (like always and complete callbacks). It's easy enough to control what state you're in from inside the callback:

  200: function() {
    if ( this.state() === "rejected" ) {
      // An client-side error occured
    } else {
      // Success!

If you used the context option then just keep a reference to the jqXHR in your closure.

Note: See TracTickets for help on using tickets.