How do I access the JSON response with jQuery.Ajax for a 400 error?

Some browsers' XHR implementations refuse to provide the response body if the HTTP status is not 2xx. What I've had to resort to in API design where I couldn't control my clients was to do something like always return 200 and indicate success/failure/status in some other way (e.g., as a top-level attribute in the JSON response).


I try to get json response with a status 400, and it works on IE7,8 and 9, Firefox and Chrome (Safari not tested).

...
error: function(xhr) {
   error(xhr.responseText);
}
...

I have had no trouble using statusCode in the callback, However, statusCode as a callback function Does NOT return any data.

jQuery.Ajax

I think you should try a different approach on how to handle validation errors in the server side, to return status code 200, but with a parameter like "error_count" and go from there.

can you post some of the code you are using (just $.ajax you are using...) ?