-
-
Save Amice13/a8a09a28694737e1a6d5f5ba713cb341 to your computer and use it in GitHub Desktop.
JS: Listen to ajax calls from Javascript
This file contains 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