Side navigation
#13917 closed bug (notabug)
Opened May 21, 2013 08:57PM UTC
Closed May 21, 2013 10:59PM UTC
Last modified May 22, 2013 01:40AM UTC
jQuery does not parse json when the response to ajax requests is unsuccessful
Reported by: | shaun.bloom@active.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
It does the dataType conversion only if ( status >= 200 && status < 300 || status === 304 ) is true otherwise the response is passed as such to the corresponding handler. That is if the request is a failure then the response is not parsed as per the expected dataType.
Attachments (0)
Change History (2)
Changed May 21, 2013 10:59PM UTC by comment:1
resolution: | → notabug |
---|---|
status: | new → closed |
Changed May 22, 2013 01:40AM UTC by comment:2
As of this commit: https://github.com/jquery/jquery/commit/eebc77849cebd9a69025996939f930cbf9b1bae1 parsed JSON is available in case of failures as the responseJSON
field of the jqXHR instance.
$.ajax( /* ... */ ).fail( function( jqXHR ) { console.log( jqXHR.responseJSON ) } );
So there's no need to do it the hard way ;)
The parsed data is only passed to the
.done()
handler anyway. If you want to do it yourself, usedataType: text
and call$.parseJSON()
on the.responseText
regardless of the HTTP code.