On the client, I am doing a standard ajax call to an MVC action.
$.ajax({
type: "POST",
url: '/FileUpload/CheckGuess/',
dataType: "json",
contentType: "application/json; charset=utf-8",
data: jsonSerialized,
success: function (result) {
console.log(result);
dfd.resolve();
},
error: function (error) {
console.log(error);
dfd.reject();
}
});
My CheckGuess action returns a JsonResult. I want to notify an ajax call that there was an error to invoke error: handler. How do I do it with HTTP response (I’ve read it’s better then sending obligatory json and parsing it in a success: handler.
you should return an error status code from the action.
For example a status 500, means an internal error in the application. You could also use some of the 400 errors as well.
The error callback should be called for any other status outside the 200 range.
The status code in the application is set to the response object.
Ref: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes