In my $.ajax I have
error: function (xhr, ajaxOptions, thrownError) {
var result = $.parseJSON(xhr.responseText);
alert(result.ErrorMessage);
}
Even though this has worked for all my previous apps, this time this choked and gave me an invalid JSON error. I am using jQuery 1.5, asp.net MVC 3.
PS: I looked at the jQuery documentation but I didn’t see the example of what JSON consumed by error should be.
What is the value in
xhr.reponseText? Just print it out using console.log(). Unless you are formatting your error pages as JSON, you’re probably getting some standard 500 HTML from the server, that’s why you can’t parse it as JSON.jQuery does not dictate the
responseTextthat is returned by the server in case of an error