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?
是否有一种方法可以通过JavaScript(客户端)检测正在发生的任何AJAX请求,甚至获取正在进行的请求数?
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.
我这样问的原因是:在一个正在与几个开发人员一起开发的应用程序中,我有一个全局处理指示器,其中一些开发人员在发出AJAX请求时忽略了启动和停止指示器。
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.
我知道最好的处理方法是用请求和请求完成时触发事件,但我无法控制其他开发人员或重写遗留代码,因此我正在寻找可以通过JavaScript注入的东西来检测请求。
1 个解决方案
#1
11
I figured it out (using jQuery):
我发现(使用jQuery):
$(document).ajaxStart(function() { /* start indicator */ });
$(document).ajaxStop(function() { /* stop indicator */ });
#1
11
I figured it out (using jQuery):
我发现(使用jQuery):
$(document).ajaxStart(function() { /* start indicator */ });
$(document).ajaxStop(function() { /* stop indicator */ });