ajax类使用过程出现的问题请教.
在执行到xmlhttp.Send()时出现对象不支持此属性和方法的错误,请大家帮看一下什么原因.我把xmlhttp.send()注掉时就没有错误提示,但肯定就没有办法完成功能了.
源码如下:
1
function ajaxSubmit(){
2
//获取用户表单的内容
3
var WillBuyId = form1.WillBuyId.value;
4
var FullName=form1.FullName.value;
5
var Tell=form1.Tell.value;
6
var Address=form1.Address.value;
7
var PostCode=form1.PostCode.value;
8
var Content=form1.Content.value;
9
var url;
10
url ="WillBuyId="+escape(WillBuyId)+"&FullName="+escape(FullName)+"&Tell="+escape(Tell)+"&PostCode="+escape(PostCode)+"&Address="+escape(Address)+"&Content="+escape(Content);
11
//创建XMLHttpRequest对象
12
var xmlhttp=new XMLHttpRequest();
13
xmlhttp.method="Post";
14
xmlhttp.url="bin/savewillBuyRe.asp";
15
xmlhttp.content=url;
16![]()
17
// 设置回调函数,输出响应内容
18
xmlhttp.callback=function(xmlobj) {
19
form1.Content.value="";
20
msg.innerHTML = "数据提交成功";
21
}
22
xmlhttp.send(); /*发送请求*/
23
}
24
</script>
25![]()
function ajaxSubmit(){2
//获取用户表单的内容3
var WillBuyId = form1.WillBuyId.value;4
var FullName=form1.FullName.value;5
var Tell=form1.Tell.value;6
var Address=form1.Address.value;7
var PostCode=form1.PostCode.value;8
var Content=form1.Content.value;9
var url;10
url ="WillBuyId="+escape(WillBuyId)+"&FullName="+escape(FullName)+"&Tell="+escape(Tell)+"&PostCode="+escape(PostCode)+"&Address="+escape(Address)+"&Content="+escape(Content);11
//创建XMLHttpRequest对象12
var xmlhttp=new XMLHttpRequest(); 13
xmlhttp.method="Post";14
xmlhttp.url="bin/savewillBuyRe.asp";15
xmlhttp.content=url;16

17
// 设置回调函数,输出响应内容18
xmlhttp.callback=function(xmlobj) {19
form1.Content.value="";20
msg.innerHTML = "数据提交成功"; 21
}22
xmlhttp.send(); /*发送请求*/23
}24
</script>25

引用的ajax.js代码如下
1
// AJAX类
2
function XMLHttpRequest() {
3
var xmlObj = false;
4
var CBfunc,ObjSelf;
5
ObjSelf=this;
6
try { xmlObj=new XMLHttpRequest; }
7
catch(e) {
8
try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
9
catch(e2) {
10
try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
11
catch(e3) { xmlObj=false; }
12
}
13
}
14
if (!xmlObj) return false;
15
this.method="POST";
16
this.url;
17
this.async=true;
18
this.content="";
19
this.callback=function(cbobj) {return;}
20
this.send=function() {
21
if(!this.method||!this.url||!this.async) return false;
22
xmlObj.open (this.method, this.url, this.async);
23
if(this.method=="POST")
24
xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
25
xmlObj.onreadystatechange=function() {
26
if(xmlObj.readyState==4) {
27
if(xmlObj.status==200) {
28
ObjSelf.callback(xmlObj);
29
}
30
}
31
}
32
if(this.method=="POST") xmlObj.send(this.content);
33
else xmlObj.send(null);
34
}
35
}
// AJAX类2
function XMLHttpRequest() {3
var xmlObj = false;4
var CBfunc,ObjSelf;5
ObjSelf=this;6
try { xmlObj=new XMLHttpRequest; }7
catch(e) {8
try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }9
catch(e2) {10
try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }11
catch(e3) { xmlObj=false; }12
}13
}14
if (!xmlObj) return false;15
this.method="POST";16
this.url;17
this.async=true;18
this.content="";19
this.callback=function(cbobj) {return;}20
this.send=function() {21
if(!this.method||!this.url||!this.async) return false;22
xmlObj.open (this.method, this.url, this.async);23
if(this.method=="POST")24
xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");25
xmlObj.onreadystatechange=function() {26
if(xmlObj.readyState==4) {27
if(xmlObj.status==200) {28
ObjSelf.callback(xmlObj);29
}30
}31
}32
if(this.method=="POST") xmlObj.send(this.content);33
else xmlObj.send(null);34
}35
}




浙公网安备 33010602011771号