Suppose that I have some global Ajax event handlers defined (ajaxStart, ajaxStop, and ajaxError). Usually I am fine with that, but for one request, I want to disable the aja
You can set $.event.global.ajaxError to false to disable invoking the global error callback temporarily. Use the error and complete callbacks of your special request to set the flags:
$.ajax({
url: 'some.domain.com/',
}).error(function(jXHR){
// Disable global error logging
$.event.global.ajaxError = false;
}).complete(function(){
// Enable global error logging
$.event.global.ajaxError = true;
});
An example is available on jsFiddle.
That being presented, I want to add that I would still prefer Jon's proposal. This technique requires to set the flag at 2 places of which you could forget one and and up to have the global handlers disabled accidentally. The other reason is that Jon's technique should be guaranteed to work across jQuery releases where setting some internal flags is not reliable.