How to send http headers with the help of javascript?
+2
A:
Sure.
var xhr = new XMLHttpRequest();
xhr.open("POST", "/path/to/script", false);
xhr.setRequestHeader("Content-Type", "text/xml");
xhr.send(strUrlEncodedPostVariables);
Be careful though. IE 5, 5.5 and 6 didn't support the XMLHttpRequest object, so you had to use new ActiveXObject() and the implementation was wonky (but worked). I don't recall how you set headers in the ActiveXObject implementation (I think it was the same), but I remember it did allow it. Strangely, the Wikipedia article on XHR is the easiest place to read up on this.
Andrew
2010-05-26 11:56:57