Hi all,
I have a website where an ajax call will get some Json data from a Asp.Net-Mvc action.
Now I'm trying to do implant errorhandling in it.
But I'm stuck at the point how to do it.
The easyst way i found, was cattch the exceptions in the controller action, and Return a Json object with an error message in. And then in the ajax succes function, I can output the error message if its excist.
But I'm not sure that's the best way, so i tried to use the error function of the ajax call.
my code is something like this:
$.ajax(
{
type: "POST",
url: "/home/geterror",
data: "",
dataType: "json",
success: function(result)
{
//do something
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert(XMLHttpRequest.responseText + " "+ XMLHttpRequest.status +" "+ textStatus +" "+ errorThrown);
}
});
I saw that the XMLHttpRequest.responseText is a standard asp.net error page with my errormessage in the title. the errorThrown is allways undefined. Now I'm trying to get the title out of the XMLHttpRequest.responseText. But I dont know how to do that. (everything i tried failed ..) So if anyone has any sugestion, or better way's to handle errors with Ajax-calls...
Thanks, Bruno