搞清楚是在不回调的一个XMLHtt prequest请求时

编程入门 行业动态 更新时间:2024-10-25 18:23:28
本文介绍了搞清楚是在不回调的一个XMLHtt prequest请求时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想超载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请求时

本文发布于:2023-06-07 15:14:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568463.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是在   回调   prequest   XMLHtt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!