我想超载XMLHtt prequest。*在JavaScript的方法,这样的网页可以计算出,如果一个Ajax请求发生,而无需使用任何侵入性回调。现在,像这样使用大多数JS框架时,工作比较细的:
I'm trying to overload the XMLHttpRequest.* method in JavaScript so a webpage can figure out if an Ajax request took place without using any intrusive callbacks. Now, something like this works relatively fine when using most JS frameworks:
XMLHttpRequest.prototype.getResponseHeader = function() { alert('O hai, looks like you made an AJAX request.'); }
然而,有两个渔获:
However, there are two catches:
- getResponseHeader不能用作 getResponseHeader 的了。
- ,它不会在简单的AJAX例子工作。即 xmlhttp.open(GET,simple.html,假);
- getResponseHeader can't be used as getResponseHeader anymore.
- It doesn't work in simple AJAX examples. i.e. xmlhttp.open("GET","simple.html",false);
有什么办法JS可以镜像 XMLHtt prequest.open()或任何方式,我可以链接的东西吧。我已经尝试了百万范式(工厂,克隆,包装 - 大多数导致无限递归)并没有什么似乎工作。也许这只是不可能的。任何想法?
Is there any way JS can mirror XMLHttpRequest.open() or any way that I can chain something to it. I've tried a million paradigms (factory, cloning, wrapping -- most resulting in infinite recursion) and nothing seems to be working. Maybe it's just impossible. Any ideas?
推荐答案您可以保留参照原有的一些变量,你覆盖的方法,然后打电话给你覆盖了函数内的变量之前:
You can keep a reference to the original in some variable before you override the method and then call that variable within the function you overrode:
var temp = XMLHttpRequest.getResponseHeader; XMLHttpRequest.getResponseHeader = function() { temp.apply(this, arguments); };这应该让你跟踪使用不带覆盖了原有的功能所提供的功能。
That should let you track uses without overriding the functionality provided by the original function.
更多推荐
搞清楚是在不回调的一个XMLHtt prequest请求时
发布评论