Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13917 closed bug (notabug)

jQuery does not parse json when the response to ajax requests is unsuccessful

Reported by: shaun.bloom@… 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.

Change History (2)

comment:1 Changed 7 years ago by dmethvin

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.

comment:2 Changed 7 years ago by jaubourg

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 ;)

Note: See TracTickets for help on using tickets.