How do I set a common request header using only JavaScript for every single HTTP call from the client side?
Asked
Active
Viewed 137 times
1 Answers
0
I don't think there is a native support for this. But on the other hand you can extend the XMLHttpRequest class so it passes your custom header and override the existing XMLHttpRequest in the window.
Take a look at this answer : https://stackoverflow.com/a/9701050
Sample:
!(send){
XMLHttpRequest.prototype.send = function (data) {
this.setRequestHeader("X-Requested-With", "XMLHttpRequest"); // set your header here
send.call(this, data);
}
}(XMLHttpRequest.prototype.send);