-
-
Save ionurboz/e61d7add9425f7693d80b2bdfd7b8dc9 to your computer and use it in GitHub Desktop.
JS: Listen to ajax calls from Javascript
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
var open = window.XMLHttpRequest.prototype.open, | |
send = window.XMLHttpRequest.prototype.send, | |
onReadyStateChange; | |
function openReplacement(method, url, async, user, password) { | |
var syncMode = async !== false ? 'async' : 'sync'; | |
console.warn( | |
'Preparing ' + | |
syncMode + | |
' HTTP request : ' + | |
method + | |
' ' + | |
url | |
); | |
return open.apply(this, arguments); | |
} | |
function sendReplacement(data) { | |
console.warn('Sending HTTP request data : ', data); | |
if(this.onreadystatechange) { | |
this._onreadystatechange = this.onreadystatechange; | |
} | |
this.onreadystatechange = onReadyStateChangeReplacement; | |
return send.apply(this, arguments); | |
} | |
function onReadyStateChangeReplacement() { | |
console.warn('HTTP request ready state changed : ' + this.readyState); | |
if(this._onreadystatechange) { | |
return this._onreadystatechange.apply(this, arguments); | |
} | |
} | |
window.XMLHttpRequest.prototype.open = openReplacement; | |
window.XMLHttpRequest.prototype.send = sendReplacement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment