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?
Asked
Active
Viewed 553 times
0
-
You can't detect such event from code embedded in webpage. – Ginden Jan 20 '15 at 10:51
-
You don't say if you are the initiator of all of these events. If you have control over the creation of these asynchronous events then you can use promises. – Klors Jan 20 '15 at 10:56
-
Did you start all the ajax calls? – Adrian Salazar Jan 20 '15 at 11:01
-
i'm not the creator of the tasks they belongs to an ASP.NET application and i need to execute something depending on their fail or success – WolFSharp Jan 20 '15 at 11:07
2 Answers
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.
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