Don Apachec
Don Apachec

Reputation: 21

http headers with the help of javascript?

How to send http headers with the help of javascript?

Upvotes: 0

Views: 142

Answers (1)

Andrew
Andrew

Reputation: 14526

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.

Upvotes: 2

Related Questions