DEV Community

Cover image for Intercept AJAX requests
Adam K Dean
Adam K Dean

Posted on

Intercept AJAX requests

Just a snippet today, a reblog, of an article on how to Hijack AJAX Requests Like A Terrorist by Daniel Huckstep.

There are some who say not to modify prototypes because you never know how other libraries will use them, but then there are also some people who think that driving 30 MPH on a 60 MPH road is a good idea, so not everything everyone thinks is a good idea, is a good idea.

(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);
Enter fullscreen mode Exit fullscreen mode

This works perfectly well for intercepting AJAX requests. In my case, it is to modify the URL that is requested by AngularJS.

Top comments (0)