html - AjaxXMLHttpRequest tracking using javascript - Stack Overflow

admin2025-04-18  0

I know firebug can trace all the Ajax/XHR events on a page. 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:

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

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? Basically i need to get what is called on button click, in this example: "/Ajax/getCall/callUser/". It should work with all buttons on my page as well.

I know firebug can trace all the Ajax/XHR events on a page. 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:

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

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? Basically i need to get what is called on button click, in this example: "/Ajax/getCall/callUser/". It should work with all buttons on my page as well.

Share edited May 9, 2015 at 21:13 George Netu 2,8326 gold badges30 silver badges51 bronze badges asked May 9, 2015 at 19:36 bpkbpk 3132 gold badges6 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

Example: http://jsfiddle/fgp783rz/1

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744931346a275175.html

最新回复(0)