I have an ajax call as below:
$.ajax({
type: "GET",
url: "process.php",
data: dataString,
success: function( response ) {
$('#in-progress').hide();
$('#mydiv').html(response)
.append("")
}
});
What I want is, that I need to get the distinguished message from process.php. What should I do in thid regard so that I may not parse the message myself. I need to send some specific code or something from my process.php so that the ajax can process it separately. Shall I use some http response code and use it in statusCode ? What is the appropriate practice to do that ?
e.g. Success message will be “This is Success”
Error message will be “There is an unknown error” – This message should be treated separately. Any idea ?
What I usually do to distinguish a success/error status from an ajax call, I return http status 500 with the error message encoded in json.
The error status 500 is being handled by the ‘error’ callback which I usually set on the $.ajaxSetup like so: