Skip to content

Instantly share code, notes, and snippets.

@arunkumr
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunkumr/79622f28011928dacc2e to your computer and use it in GitHub Desktop.
Save arunkumr/79622f28011928dacc2e to your computer and use it in GitHub Desktop.
var oldXHR = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function () {
//Insert code to run when new XHR request is created
XHRCreated();
oldXHR.apply(this, arguments);
var oldReadSta = this.onreadystatechange;
this.onreadystatechange = function () {
oldReadSta.apply(this, arguments);
if (this.readyState == 4 && this.status == 200) {
//Insert code to run when the XHR request is completed
XHRClosed();
}
}
}
function XHRCreated()
{
alert('XML HTTP request created');
}
function XHRClosed()
{
alert('XML HTTP request completed');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment