0

I have to detect all ajax requests that are made in a specific web page (long story). The idea that I came with is overriding XMLHttpRequest.

I developed a simple script that does what I need. It works flawlessly on Firefox, Chrome, and Opera, but not on Internet Explorer. IE simply ignores the behavior I override.

How can I override XMLHttpRequest on Internet Explorer?

On Chrome (works):

On IE (doesn't work):

talles
  • 14,356
  • 8
  • 45
  • 58

2 Answers2

0

If you are trying to detect it, you can override the open method.

(function(){
  var oOpen = XMLHttpRequest.prototype.open;
  XMLHttpRequest.prototype.open = function() {
    console.log("here");
    oOpen.apply(this, arguments);
  };
}());
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • It also doesn't work on IE... I'm overriding the `send` method by the way, the ctor overriding is just an easy to reproduce example. – talles Nov 29 '16 at 11:13
  • You might need to do it this way also http://stackoverflow.com/questions/797960/extending-an-activexobject-in-javascript – epascarello Nov 29 '16 at 12:27
0

I had the same problem with IE9. Switch to IE11 and it will work fine.