Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect AJAX requests in the browser (client side)

Is there a way to detect via JavaScript (client side) any AJAX requests that are occurring and even get the number of requests in progress?

The reason I ask: I have a global processing indicator in an application being worked on with several developers, some of whom neglect to start and stop the indicator when making AJAX requests.

Is there a way to detect this?

I know the best way to handle it would be to trigger something with the requests and when the requests complete, but I can't control the other developers or rewrite legacy code, so I'm looking for something I can inject in with JavaScript to detect requests.

like image 263
Kristopher Avatar asked Apr 26 '10 17:04

Kristopher


1 Answers

I figured it out (using jQuery):

$(document).ajaxStart(function() { /* start indicator */ });

$(document).ajaxStop(function() { /* stop indicator */ });
like image 132
Kristopher Avatar answered Oct 05 '22 18:10

Kristopher