AllThingsSmitty/jquery-tips-everyone-should-know

Ajax calls enhancement

leroy0211 opened this issue · 1 comments

When using an Ajax call, always use an error handler!
When an ajax call returns a 404 or 500 error, the error handler will be executed. If the handler is not defined, sometimes other javascript/jquery wont work anymore. I'm not sure if this is the case with jquery 2, but I have seen this problem before.

You can define a global ajax error handler in jquery by:

$(document).ajaxError(function(e, xhr, settings, error){
    console.log(error);
});

@leroy0211 excellent idea, thanks!