主题:xmlhttp 的setRequestHeader报错提示是未指定的错误。
xmlhttp 的setRequestHeader报错提示是未指定的错误。
代码如下:
<html>
<head><title>显示框架</title>
</head>
<body >
<form name="myform" id="myform" action="getcustomerdata.asp" method="post" target="hiddenframe" >
<input type="text" name="name1" id="name1" />
<input type="text" name="sex" id="sex" />
<input type="button" name="tijiao" id="tijiao" value="提交" onClick="sendrequest();return false;" />
</form>
<script language="javascript">
function checkiframe(ofrom){
var aparams=new Array(); //创建一个数组
for(var i=0;i<ofrom.elements.length;i++){
var sparam=encodeURIComponent(ofrom.elements[i].name); //取得表单元素名
sparam+="="; //名与值之间用"="号连接
sparam+=encodeURIComponent(ofrom.elements[i].value); //获得表单元素值
aparams.push(sparam); //push是把新元素添加到数组中去
}
return aparams.join("&"); //那数组中的值连接起来 并用"&"连接起来
}
function sendrequest(){
var omysfrom=document.forms[0];
var sbody=checkiframe(omysfrom); //就是表单的名和值组成的字符串
var oxmlhttp=new ActiveXObject("microsoft.XmlHttp");
oxmlhttp.open("POST","getcustomerdata.asp",true);
oxmlhttp.send(sbody); //sbody就是主体了,get是传一个null值过去
oxmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
oxmlhttp.onreadystatechange=function(){
if(oxmlhttp.readystate==4){
if(oxmlhttp.status==200){
alert(oxmlhttp.responseText);
}
else{
alert(oxmlhttp.statusText);
}
}
};
}
</script>
</body>
</html>
就是这句报错。 oxmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
但要是不加这句post上传后台就用from得不到值了。
因该怎么解决这个错误呢。
代码如下:
<html>
<head><title>显示框架</title>
</head>
<body >
<form name="myform" id="myform" action="getcustomerdata.asp" method="post" target="hiddenframe" >
<input type="text" name="name1" id="name1" />
<input type="text" name="sex" id="sex" />
<input type="button" name="tijiao" id="tijiao" value="提交" onClick="sendrequest();return false;" />
</form>
<script language="javascript">
function checkiframe(ofrom){
var aparams=new Array(); //创建一个数组
for(var i=0;i<ofrom.elements.length;i++){
var sparam=encodeURIComponent(ofrom.elements[i].name); //取得表单元素名
sparam+="="; //名与值之间用"="号连接
sparam+=encodeURIComponent(ofrom.elements[i].value); //获得表单元素值
aparams.push(sparam); //push是把新元素添加到数组中去
}
return aparams.join("&"); //那数组中的值连接起来 并用"&"连接起来
}
function sendrequest(){
var omysfrom=document.forms[0];
var sbody=checkiframe(omysfrom); //就是表单的名和值组成的字符串
var oxmlhttp=new ActiveXObject("microsoft.XmlHttp");
oxmlhttp.open("POST","getcustomerdata.asp",true);
oxmlhttp.send(sbody); //sbody就是主体了,get是传一个null值过去
oxmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
oxmlhttp.onreadystatechange=function(){
if(oxmlhttp.readystate==4){
if(oxmlhttp.status==200){
alert(oxmlhttp.responseText);
}
else{
alert(oxmlhttp.statusText);
}
}
};
}
</script>
</body>
</html>
就是这句报错。 oxmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
但要是不加这句post上传后台就用from得不到值了。
因该怎么解决这个错误呢。