使用Javascript拦截或捕获Ajax调用 [英] Intercept or catch Ajax Calls with Javascript

查看:63
本文介绍了使用Javascript拦截或捕获Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建一个Javascript并将其包含在一个网页中,该JS的功能是捕获所有GET请求或从页面上的任何其他Javascript进行的任何其他Ajax调用?要么记录它,要么只是在警告框中显示它。

Is it possible to create a Javascript and include it in a web page that the function of this JS is to "catch" all GET request or any other Ajax calls made from any other Javascript on the page? Either to log it or just plain show it in a Alert box.

将执行GET或Ajax调用的其他Javacript是任意的。我的意思是我无法控制它是什么。

The "other Javacript" that will be executing GET or Ajax calls is arbitrary. I mean I have no control over that in terms of what it is.

一旦被捕,我需要检查哪个Javascript执行哪个GET或Ajax调用。

And once caught I need to check which Javascript executing which GET or Ajax calls.

这可能吗?

推荐答案

试试这个片段。它扩展了发送函数,以便您可以在实际发送之前或之后执行某些操作。

Try this snippet. It extends the send function so that you can execute something before or after the real sending.

XMLHttpRequest.prototype.reallySend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(body) {
    // Do something...
    this.reallySend(body);
};
var req = new XMLHttpRequest();
req.open("GET", "any.html", true);
req.send(null);

这篇关于使用Javascript拦截或捕获Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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