I want to alert the user whenever there's an AJAX error. You can do this via $.ajaxSetup
:
$.ajaxSetup({
error: function() {
alert("OOPS!")
}
});
But the jQuery docs recommend against this:
Note: Global callback functions should be set with their respective global Ajax event handler methods-.ajaxStart(), .ajaxStop(), .ajaxComplete(), .ajaxError(), .ajaxSuccess(), .ajaxSend()-rather than within the settings object for $.ajaxSetup().
So I guess I'm supposed to do this:
$("#some_random_div").ajaxError(function() {
alert("OOPS!")
});
This doesn't make sense to me: the AJAX error callback pertains to my application as a whole, not a specific page element. So why should the callback function be associated with an individual page element?
So: why do the jQuery docs recommend using what looks like a less readable approach, and which approach is best?