This is super old, but hopefully this helps somebody. I'm sending responses with different error codes back and this is the only solution I've found that works in
$.ajax({
data: {
"data": "mydata"
},
type: "POST",
url: "myurl"
}).done(function(data){
alert(data);
}).fail(function(data){
alert(data.responseText)
});
Since JQuery deprecated the success
and error
functions, it's you need to use done
and fail
, and access the data with data.responseText
when in fail
, and just with data
when in done
. This is similar to @Marco Pavan 's answer, but you don't need any JQuery plugins or anything to use it.