Created
July 26, 2012 16:47
-
-
Save icodejs/3183154 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; |
Thank you!
Awesome work! Thanks.
Thanks
More generic approach https://stackoverflow.com/a/72555729
Server invalidates cookies at 30 minutes. I used a ping function to keep login active for some users. Now I want to use a timer instead but ajax calls are happening all over so a listener to reset a timer yielding time lapsed since last ajax call should solve this nicely.
Thank you very much.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/a/6036392/383904