时间:2023-12-12 02:00:33 下载该word文档
js建立XMLHttpRequest对象及其属性和方法1.//定义变量,存储对象2.varxmlHttp;3.//创建XMLHttpRequest对象4.functioncreatXMLHttpRequest(5.{6.if(window.ActiveXObject7.{8.xmlHttp=newActiveXObject("Microsoft.XMLHTTP";9.}10.elseif(window.XMLHttpRequest11.{12.xmlHttp=newXMLHttpRequest(;13.}14.}15.//使用get方式建立与后台的交互16.functioncallServer(17.{18.creatXMLHttpRequest(19.varemail=document.getElementById("TxtEmail".value;20.if(email==""21.{22.document.getElementById("LabMsg".innerText="请输入邮箱!";23.document.getElementById("LabMsg".style.color="red";24.}25.else26.{27.url="register.aspx?email="+email+"&ts"+newDate(.getTime(;28.xmlHttp.onreadystatechange=handleStateChange;29.xmlHttp.open("GET",url,true;30.xmlHttp.send(null;31.}32.}33.//回调函数,后台处理完结果后返回给回调函数34.functionhandleStateChange(35.{36.//请求的状态有5个值:0=未初始化;1=正在加载;2=已经加载;3=交互中;4=完成;37.if(xmlHttp.readyState==438.{
39.//200对应OK,如404=未找到网页40.if(xmlHttp.status==20041.{42.varresult=xmlHttp.responseXML.getElementsByTagName("result"[0].firstChild.nodeValue;43.if(result=="true"44.{45.document.getElementById("LabMsg".innerHTML="恭喜,可用!";46.document.getElementById("LabMsg".style.color="red";47.