简体   繁体   English

使用javascript进行Ajax / XMLHttpRequest跟踪

[英]Ajax / XMLHttpRequest tracking using javascript

I know firebug can trace all the Ajax/XHR events on a page. 我知道firebug可以跟踪页面上的所有Ajax / XHR事件。 But I need to prepare a tool which automatically tracks these calls on button clicks on an already existing webpage. 但是我需要准备一个工具,该工具可以自动跟踪已经存在的网页上的按钮点击。

My webpage's HTML and JS structure are follows: 我的网页的HTML和JS结构如下:

HTML: HTML:

<a href="javascript:void(0)" id="callButton" class=" call-btn " style="width: 30px;">Call</a>

JS: JS:

scope: this,
id: 'callButton',
handler: function () {
    Ext.Ajax.request({
        url: '/Ajax/getCall/callUser/',
        params: {
            userID: usr.id
        },

Can anyone suggest how to track this ajax calls with the help of another javascript or something? 任何人都可以建议如何借助其他JavaScript或其他工具来跟踪此ajax调用吗? Basically i need to get what is called on button click, in this example: "/Ajax/getCall/callUser/". 基本上,我需要获得按钮单击时的调用,在此示例中:“ / Ajax / getCall / callUser /”。 It should work with all buttons on my page as well. 它也应该与我页面上的所有按钮一起使用。

Add at start of your script this: 在脚本开始处添加以下内容:

XMLHttpRequest.prototype.oldSend = XMLHttpRequest.prototype.send
XMLHttpRequest.prototype.send = function (data) {
    // there you can log requests
    console.log("AJAX request was sent.");
    this.oldSend.call(this, data);
}

This creates copy of send method on XMLHttpRequest object and internal method replaces by method where you can log AJAX requests and this method call the internal method whitch send AJAX request. 这将在XMLHttpRequest对象上创建send方法的副本,内部方法替换为可以记录AJAX请求的方法,并且此方法调用内部方法whitch send AJAX请求。

Example: http://jsfiddle.net/fgp783rz/1 示例: http//jsfiddle.net/fgp783rz/1

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

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