简体   繁体   English

在浏览器中检测AJAX请求(客户端)

[英]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.

相关问题 客户端验证和Ajax请求 - client side validations and ajax requests Ajax请求和竞争条件(客户端和服务器端) - Ajax requests and racing conditions (client and server side) 是否有一个javascript客户端库,用于排队具有存储支持的ajax请求 - Is there a javascript client-side library for queuing ajax requests with storage support 客户端上的AJAX加载解决方法 跨源请求错误 - AJAX Load on the client side workaround | Cross Origin requests error 来自客户端访问API的AJAX请求的安全性 - Security for AJAX requests from the client side accessing an API AJAX jQuery发布数据对于浏览器/客户端操作是否安全? - Is AJAX jquery post data safe for browser/client-side manipulation JavaScript:检测 AJAX 请求 - JavaScript: Detect AJAX requests 在服务器端(PHP)或客户端(Javascript)上检测移动浏览器更好/更快吗? - Is it better/faster to detect mobile browser on server side (PHP) or client side (Javascript)? RESTful客户端中的Ajax请求 - Ajax requests in the RESTful client Internet Explorer浏览器问题:浏览器未通过Ajax请求提交POST数据,服务器/客户端挂起 - Internet Explorer Browser Issue: Browser not submitting POST data with Ajax requests, server/client hangs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM