Adam K Dean

Intercepting XMLHttpRequest requests

Published on 11 March 2015 at 12:20 by Adam

Let's kick off the continuation of my code blogging with a very helpful little snippet. I'm just removing this from a codebase so it can sit here for eternity instead.

(function(open) {
    XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
        // do some magic
        open.call(this, method, url, async, user, pass);
    };
})(XMLHttpRequest.prototype.open);

This will intercept the request before it happens, and once you've done whatever changes you need to do, be it logging or tagging, you can continue it.



This post was first published on 11 March 2015 at 12:20. It was filed under archive with tags javascript.