Last active
August 29, 2015 14:18
-
-
Save arunkumr/79622f28011928dacc2e to your computer and use it in GitHub Desktop.
Cross browser and cross framework solution for listening to XML Http requests. From http://stackoverflow.com/questions/23674175/in-javascript-how-can-i-test-if-any-ajax-call-is-running-in-the-background-at-a/23674587#23674587
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 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