How can I know that no one AJAX request is being executed right now or all AJAX requests are completed?
I need to write an if
statement. I need js native or jquery.
Like:
if(```no ajax pending```){ //do some }
Thanks!
Advertisement
Answer
You can set up events that track ajax requests in jquery
https://api.jquery.com/ajaxstart/
https://api.jquery.com/ajaxstop
let ajaxRunning = false ; $( document ).ajaxStart(function() { ajaxRunning = true; }).ajaxStop(function() { ajaxRunning = false; }); if (!ajaxRunning) { // nothin doin }
ajaxStop
gets tripped when all requests have been completed