[英]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? 有没有办法通过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注入的东西检测请求。
I figured it out (using jQuery): 我想通了(使用jQuery):
$(document).ajaxStart(function() { /* start indicator */ });
$(document).ajaxStop(function() { /* stop indicator */ });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.