$.post('/echo/json/', {json:JSON.stringify({'error':true})}) .done(function (response) { //Our JSON response will come back with an http status of 200, // so we have to handle our errors in the "done" (success) // callback of the promise returned by post(). if (response.error) { $("#status").html("An error occurred"); } else { $("#status").html("Success!"); } }) .fail(function (response) { //This gets executed on failing http status codes (e.g. 400) $("#status").html("A server error occured (failing http status code)"); });
<div id="status"></div>