日期:2014-05-16  浏览次数:20324 次

Firefox中XMLHttpRequest返回结果在错误控制台报--语法错误
test.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
<script type="text/javascript">
function test(){
 var xmlHttp=null;
 if(window.XMLHttpRequest){
    xmlHttp=new XMLHttpRequest();
 }else if(window.ActiveXObject){
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 var url="called.html";
 xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    alert(xmlHttp.responseText);
}
 };
 xmlHttp.open("GET",url,true);
 xmlHttp.setRequestHeader("Content-Type", "application/text");
 xmlHttp.setRequestHeader("Accept","application/text");
 xmlHttp.send(null);
}
</script>
</head>
<body onload="test()">
</body>
</html>

called.html

result

我经常有这样的请求,返回结果均为plain text,在Firefox错误控制台中一直报错----
错误: 语法错误
result

请问我设置了xmlHttp.setRequestHeader("Content-Type", "application/text");
 xmlHttp.setRequestHeader("Accept","application/text");
怎么都无效?
为何用jquery不会发生这样的语法错误?
原生xmlHttp怎么避免这样的语法错误

------解决方案--------------------
回结果均为plain text,在Firefox错误控制台中一直报错----
错误: 语法错误
re:
不是提示你返回的结果有错误吗?你设置setRequestHeader对它有用吗