I have prototyped the XMLHttpRequest to add additional functionalities.
But when I try to add a custom header to the call it does not work (no errors and no calls in the chrome developer toolbar)
My code:
(function(){
var originalOpenFunction = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
//Add custom header
this.setRequestHeader('custom-header', 'value');
originalOpenFunction.call(this, method, url, async, user, pass);
};
})();
$.ajax("http://www.jsfiddle.net");
When I remove the setRequestHeader line, I get the error I expected (cross-origin not allowed).
Note Although I use jquery to test the javascript, the solution to this should be in native javascript.