0

it's all in the title. I need to know when all asynchronous tasks are finished on my web page. Is it possible with a kind of custom listener or something?

Nima Derakhshanjan
  • 1,380
  • 9
  • 24
  • 37
WolFSharp
  • 169
  • 4
  • 14

2 Answers2

1

There doesn't exist a reliable and standard way to detect the finish of all asyncronous tasks. If you're using javascript in your webpage then the scripts can run new asynchronous requests at any time, based on their functionality.

If you're using jQuery and all requests are initiated by you, take a look at this answer.

Community
  • 1
  • 1
sc3w
  • 1,154
  • 9
  • 21
0

You can use something like that:

var ajaxfinished = 0;
var totalAjax = 5; //Total of ajax functions you have

$( document ).ajaxComplete(function() { //Listener for a complete Ajax function
  ajaxFinished += 1;
  if (ajaxFinished == totalAjax) { //here you know that all tasks are finish
      //run your code
  }
});

Take a look here to .ajaxComplete, the major con of do that if that you will be very careful with totalAjax.

ppascualv
  • 1,137
  • 7
  • 21