Skip to content

Instantly share code, notes, and snippets.

@rolfen
Forked from icodejs/ajaxListener.js
Last active October 10, 2017 15:15
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 rolfen/f73bcd6eb4b476d6debded5dac58fc2c to your computer and use it in GitHub Desktop.
Save rolfen/f73bcd6eb4b476d6debded5dac58fc2c to your computer and use it in GitHub Desktop.
JS: Listen to ajax calls from Javascript
// override XMLHttpRequest
// source: https://gist.github.com/icodejs/3183154
var open = window.XMLHttpRequest.prototype.open,
send = window.XMLHttpRequest.prototype.send;
function openReplacement(method, url, async, user, password) {
return open.apply(this, arguments);
}
function sendReplacement(data) {
this.addEventListener('readystatechange', function() {
// Catch response here
}, false);
return send.apply(this, arguments);
}
window.XMLHttpRequest.prototype.open = openReplacement;
window.XMLHttpRequest.prototype.send = sendReplacement;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment