一个客户端的验证小程序ajax

时间:2011-11-01 10:11:29
【文件属性】:

文件名称:一个客户端的验证小程序ajax

文件大小:4KB

文件格式:RAR

更新时间:2011-11-01 10:11:29

一个客户端的验证小程序ajax

一个客户端的验证小程序ajax function Go() { //第一步 初始化 createXMLHttpRequest(); //第二步 取得表单中需要的数据 var newName =document.f3.uname.value; //第三步 建立要连接的URL并打开服务器的连接(并传值) var url = "regServer.jsp?uname="+newName; //var url="regServer.jsp"; req.open("POST",url); //第四步 设置服务器在完成后要运行的函数(设置回调函数) req.onreadystatechange = getReadyStateHandler; //req.onreadystatechange = getReadyStateHandler(); //req.onreadystatechange = getReadyStateHandler(req,responseXmlHandler); //设置头信息,用send()传值如果没有这句话传值将为null //req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //第五步 发送请求 (输入数据) req.send(); //var newName ="uname=" + document.f3.uname.value; //req.send(newName); } //创建XMLHttpRequest对象 function createXMLHttpRequest() { if(window.XMLHttpRequest) { //Mozilla 浏览器 req = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE浏览器 try { //较新版本的 req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { //低版本的 req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } } // 第六步 编写回调函数,处理服务器返回的结果 function getReadyStateHandler() { //function getReadyStateHandler(req, responseXmlHandler) { // Return an anonymous function that listens to the XMLHttpRequest instance //return function () { //判断status对象状态 if (req.readyState == 4) { // 信息已经成功返回 if (req.status == 200) { var reqtxt = req.responseText; //处理服务器返回的结果 var showMsgArea = document.getElementById("msg");//找到要显示服务器信息的节点 showMsgArea.innerHTML = reqtxt;//设置显示信息 } else { //HTTP问题 alert("HTTP error "+req.status+": "+req.statusText); } } }


【文件预览】:
demoAjax
----.project(1KB)
----.mymetadata(288B)
----WebRoot()
--------reg.jsp(3KB)
--------regServer.jsp(594B)
--------WEB-INF()
--------META-INF()
----.myeclipse()
----src()
----.classpath(340B)

网友评论