yatin
yatin

Reputation: 1

javascript ajax interception

I am using the following javascript code to intercept ajax calls:

XMLHttpRequest.prototype.realOpen = XMLHttpRequest.prototype.open;
var newOpen = function(method, url, async, user, password) {
    console.log("Intercepted open (" + url + ")");
    this.realOpen(method, url, async, user, password);
}
XMLHttpRequest.prototype.open = newOpen;

The javascript which performs the ajax calls and the above code are loaded from:
https://example.com/js/main.js
https://example.com/js/intercept.js

The above code works well when the domain for ajax call is just "example.com", but when the ajax call is made for the domain "sub.example.com" the above code is not able to intercept that request.

Does anybody know why it would not work?

Upvotes: 0

Views: 555

Answers (1)

Christophe
Christophe

Reputation: 28174

It seems that you are victim of the same origin policy, as example.com and sub.example.com are considered two different domains.

Upvotes: 1

Related Questions