jQuery post fail callback does not display response for code 400

Viewed 26212

I have a following jQuery post request:

$.post("ajax.php", data).done(
    function(response){
        // do something when response is ok
     }
   ).fail(
    function(response){
          $("#error").html(response);
     }
 );

In my ajax.php file when something goes wrong I return HTTP response code 400 with a message:

header("HTTP/1.0 400 Error");
echo "Some error message";
exit();

When I check the response for faulty call in my browser I can see the status code Status Code:400 Bad Request and a response text I passed in error message. But the jQuery's .fail callback is not displaying my response.

How can I get the access to the fail/error response text?

EDIT

I tested my code and the .fail callback is being triggered, I just cannot get the response message being displayed.

2 Answers
Related