How to se开发者_C百科nd http headers with the help of javascript?
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.
精彩评论