ajax setRequestHeader选项

时间:2012-08-07 10:44:15

标签: ajax object xmlhttprequest

以下是关于AJAX的访谈问题。我应该更正代码:

httpconn.open('POST','http://mysecondserver.com/listen/xxx.php',true,'username','password');

httpconn.setRequestHeader('Accept-Encoding','auto');
httpconn.setRequestHeader('Content-type', 'text/plain');
httpconn.setRequestHeader('Content-length', data.length);

httpconn.send(data);

我想知道是否可以在httpconn.open中指定用户名和密码?

setRequestHeaders怎么样?他们是对的吗?我肯定知道httpconn.setRequestHeader('Content-type','text / plain');是正确的。那么另外两个呢?

谢谢。

1 个答案:

答案 0 :(得分:0)

用户名和密码有效:
http://en.wikipedia.org/wiki/XMLHttpRequest#The_open_method

根据W3C,以下标题无效,应抛出异常:
内容长度,接受编码
http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method