Pradip
Pradip

Reputation: 1327

how to capture the event of all ajax requests are received

I use JQuery. There is a widget based application. There are multiple widgets on single page. Every widget contains N number of ajax request while loading the widgets.

How can i capture the event when result of all ajax request are received? Is there any way without timer?

Upvotes: 2

Views: 267

Answers (1)

Vivek S
Vivek S

Reputation: 5550

The foolowing jquery method will be called on complete of every ajax request. If you know the number of ajax requests. so you can have a global variable and increment it on every call until it reaches the desired value and then trigger your desired event

var i=0;
$("body").ajaxComplete(function(event,request, settings) {
  if(i==MAX_REQ){
    alert("done all");
  }
  else {
    i+=1;
  }

});

Upvotes: 4

Related Questions