I'm trying to return a useful error message to my AJAX requests that I can use client side to display to the user.
I'm making my requests using jQuery like the following:
$.ajax({
url: 'myURL.php',
data: { id: someId },
type: 'POST',
success: function(response) {
// do something with response
},
error: function(jqXHR) {
// here is where I want to do something with jqXHR.responseText
// but how do I set that in PHP?
}
});
And if some error occurs in my PHP script, I use the following header:
header("HTTP/1.1 500 Internal Server Error");
So my question is, how do I include some useful error message in that header that will get put onto the responseText attribute of the jqXHR which I can then use in my jQuery error callback?
Any help is appreciated.