Skip to content

Instantly share code, notes, and snippets.

@pemre
Last active February 6, 2019 15:40
Show Gist options
  • Save pemre/e29471c2412e08a37c94b681b9116d90 to your computer and use it in GitHub Desktop.
Save pemre/e29471c2412e08a37c94b681b9116d90 to your computer and use it in GitHub Desktop.
// @source answer https://stackoverflow.com/a/27363569/7325594
// @source question https://stackoverflow.com/questions/5202296/add-a-hook-to-all-ajax-requests-on-a-page
(function () {
var origOpen = XMLHttpRequest.prototype.open
XMLHttpRequest.prototype.open = function () {
console.log('request started!')
this.addEventListener('load', function () {
console.log('request completed!')
console.log(this.readyState) // will always be 4 (ajax is completed successfully)
console.log(this.responseText) // whatever the response was
})
origOpen.apply(this, arguments)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment