views:

156

answers:

1

I have an application utilizing lots of AJAX requests (different actions are triggered via XHR requests). Some of those calls may result in exceptions. Each time I have to display an error message to the user. How can I organize error handling in this case?

A: 

Can I recommend that you use something like jQuery. They have taken all the hard thinking away from you. That and they have added a nice layer in between us and multiple browsers. They get it right 99% of the time. Anyway, you can make an ajax call very simply:

jQuery.ajax({
    type: "POST",
    url: "saveuser.do",
    dataType:"html",
    success:function(response){},
    error:function (){
      alert("error");
    }
});

Sorry if the syntax is not 100%, doing it from memory

uriDium