如何在没有 jQuery 的情况下模拟 ajaxStart 和 ajaxStop? [英] How can I emulate ajaxStart and ajaxStop without jQuery?

查看:37
本文介绍了如何在没有 jQuery 的情况下模拟 ajaxStart 和 ajaxStop?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看 jQuery 代码,但它有点庞大.这会是一件容易的事吗?知道怎么做吗?

I've been looking at the jQuery code but is kinda huge. Would this be an easy task? Any idea how to do it?

我想这样做的原因是因为我不想将它用于网页,而是用于需要知道 WebBrowser.所以我会在任何想要检测 ajax 活动的网页中注入我的 javascript 代码,而不是注入可能已经存在并导致冲突的整个 jQuery.

The reason I want to do this is because I want to use it not for a web page but for a C# application that needs to know when there is ajax activity going on in a WebBrowser. So I would inject my javascript code in any web page I want to detect ajax activity, instead of injecting the whole jQuery which might be already present and cause a conflict.

推荐答案

jQuery 的 ajaxStart 不会为任意的 XMLHttpRequest 事件触发,只为来自 jQuery 的事件触发.

jQuery's ajaxStart doesn't fire for arbitrary XMLHttpRequest events, only for those coming from within jQuery.

您可以通过在注册 ajaxStart 处理程序后启动您自己的 XMLHttpRequest 来轻松测试*.

You can trivially test* this by spinning up your own XMLHttpRequest after registering an ajaxStart handler.

因此,从技术上讲,它很容易模仿:只需通过一种通用方法路由所有 ajax 流量即可.

So, technically, its easy to emulate: just route all your ajax traffic through a common method.

我怀疑这对您有多大帮助,因为您实际上不会捕获所有 ajax 请求,只是您启动的那些请求(因此根据定义已经知道).

I doubt that's going to help you much since you won't actually capture all ajax requests, just the ones you kick off (and thus already know about, by definition).

*我做了,因为我不确定.

这篇关于如何在没有 jQuery 的情况下模拟 ajaxStart 和 ajaxStop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆