Skip to main content

Bug Tracker

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 dmethvin comment:1

resolution: → notabug
status: newclosed

The parsed data is only passed to the .done() handler anyway. If you want to do it yourself, use dataType: text and call $.parseJSON() on the .responseText regardless of the HTTP code.

Changed May 22, 2013 01:40AM UTC by jaubourg 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 ;)