简体   繁体   English

JavaScript中用于XMLHttpRequest或ActiveXObject的jQuery .ajaxComplete()的替代方法

[英]Alternative to .ajaxComplete() of jQuery in JavaScript for XMLHttpRequest or ActiveXObject

When we use $.ajax object it is easy to use .ajaxComplete() to detect ajax request from any handler of document. 当我们使用$ .ajax对象时,很容易使用.ajaxComplete()来检测来自任何文档处理程序的ajax请求。

Is what we are working with javaScript only, no jQuery, how can we achieve same result like .ajaxComplete(). 这是我们仅使用javaScript而不使用jQuery的方法,我们如何获得类似.ajaxComplete()的结果。

You could do what jQuery did and create your own wrapper around XHR/ActiveX. 您可以执行jQuery的操作,并围绕XHR / ActiveX创建自己的包装器。 Make sure you use it exclusively in your application and then you can have it do whatever you want (including calling back registered functions) whenever it completes a request. 确保仅在应用程序中使用它,然后在完成请求时就可以让它做任何您想做的事情(包括回叫注册函数)。

Edit: If you want to capture ANY xhr completion, check out this fiddle I made: https://jsfiddle.net/0bjfLey9/1 . 编辑:如果要捕获任何xhr完成,请检查我做的这个小提琴: https : //jsfiddle.net/0bjfLey9/1 Basically you wrap the send() function and then wrap the onreadystatechange handler, inserting whatever logic you want into the wrapper. 基本上,您包装send()函数,然后包装onreadystatechange处理程序,将所需的任何逻辑插入包装器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM