-
-
Save im-noob/4a884b777712669c8a9fc191c4760ee9 to your computer and use it in GitHub Desktop.
Detect any XMLHttpRequests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From: http://stackoverflow.com/questions/3596583/javascript-detect-an-ajax-event | |
var s_ajaxListener = new Object(); | |
s_ajaxListener.tempOpen = XMLHttpRequest.prototype.open; | |
s_ajaxListener.tempSend = XMLHttpRequest.prototype.send; | |
s_ajaxListener.callback = function () { | |
// this.method :the ajax method used | |
// this.url :the url of the requested script (including query string, if any) (urlencoded) | |
// this.data :the data sent, if any ex: foo=bar&a=b (urlencoded) | |
console.log(this.method); | |
console.log(this.url); | |
console.log(this.data); | |
} | |
XMLHttpRequest.prototype.open = function(a,b) { | |
if (!a) var a=''; | |
if (!b) var b=''; | |
s_ajaxListener.tempOpen.apply(this, arguments); | |
s_ajaxListener.method = a; | |
s_ajaxListener.url = b; | |
if (a.toLowerCase() == 'get') { | |
s_ajaxListener.data = b.split('?'); | |
s_ajaxListener.data = s_ajaxListener.data[1]; | |
} | |
} | |
XMLHttpRequest.prototype.send = function(a,b) { | |
if (!a) var a=''; | |
if (!b) var b=''; | |
s_ajaxListener.tempSend.apply(this, arguments); | |
if(s_ajaxListener.method.toLowerCase() == 'post')s_ajaxListener.data = a; | |
s_ajaxListener.callback(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Love This