Reputation: 612
I want to have a function called for every ajaxComplete call regardless of the ajax call. I know I can set a default value using my spinner by saying ('#spinner').ajaxComplete(complete) however if I have an ajax request that implements it's own complete my default complete method is not called.
How can I make a central function get called when any ajax call has completed??
Upvotes: 1
Views: 202
Reputation: 50797
Attach the ajaxComplete listener to the DOM. This allows us to monitor it for any
$(document).ajaxComplete(function(e,request, options){
//attach our listener for ajaxComplete to the DOM.
//whenever an ajax call is completed, the DOM will send this function
customAjaxCompleteFunction();
});
var customAjaxCompleteFunction = function(){
alert("Custom Function for Each ajax call on complete!");
}
Upvotes: 2
Reputation: 3319
Attach your ajaxComplete to the document; the ajax event will bubble up:
$(document).ajaxComplete(function(e, xhr, settings) {
// Do whatever you need here.
});
Upvotes: 2