Skip to content

Instantly share code, notes, and snippets.

@limitedeternity
Last active May 15, 2018 16:11
Show Gist options
  • Save limitedeternity/e96916c54aa656a80df564897ce51d90 to your computer and use it in GitHub Desktop.
Save limitedeternity/e96916c54aa656a80df564897ce51d90 to your computer and use it in GitHub Desktop.
function addXMLRequestCallback(callback) {
var oldSend, i;
if (XMLHttpRequest.callbacks) {
XMLHttpRequest.callbacks.push(callback);
} else {
XMLHttpRequest.callbacks = [callback];
oldSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function () {
for (i = 0; i < XMLHttpRequest.callbacks.length; i++) {
XMLHttpRequest.callbacks[i](this);
}
oldSend.apply(this, arguments);
}
}
}
addXMLRequestCallback(function(xhr) {
if (xhr.__state) {
console.dir(xhr.__state);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment