Side navigation
#12551 closed bug (notabug)
Opened September 17, 2012 06:08PM UTC
Closed September 17, 2012 11:26PM UTC
jQuery.ajax 2xx statusCode callbacks are invoked with error-callback parameters when parsererror is raised
Reported by: | karns.17@gmail.com | Owned by: | karns.17@gmail.com |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.8.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
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).
Attachments (0)
Change History (2)
Changed September 17, 2012 07:17PM UTC by comment:1
owner: | → karns.17@gmail.com |
---|---|
status: | new → pending |
Changed September 17, 2012 11:26PM UTC by comment:2
resolution: | → notabug |
---|---|
status: | pending → closed |
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.
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.