Last active
February 6, 2019 15:40
-
-
Save pemre/e29471c2412e08a37c94b681b9116d90 to your computer and use it in GitHub Desktop.
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
// @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