手机
当前位置:查字典教程网 >编程开发 >AJAX相关 >使用Ajax技术通过XMLHttpRequest对象完成首页登录功能
使用Ajax技术通过XMLHttpRequest对象完成首页登录功能
摘要:最近使用Ajax技术通过XMLHttpRequest对象完成一个首页的登录功能!代码如下://创建XMLHttpRequest对象funct...

最近使用Ajax技术通过XMLHttpRequest对象完成一个首页的登录功能!

代码如下:

<script type="text/javascript"> //创建XMLHttpRequest对象 function createXMLHttpRequest(){ if(window.XMLHttpRequest){ return xmlhttprequest=new XMLHttpRequest(); }else{ return xmlhttprequest=new ActiveXObject("Microsoft.XMLHTTP"); } } //登录按钮执行的方法 function doStart(){ var logname=document.getElementById("loginName").value; var logpass=document.getElementById("loginPsw").value; var userinfo="inAccount="+logname+"&inPsw="+logpass; var url="users/users_pswCheck.action"; xmlhttprequest=createXMLHttpRequest(); xmlhttprequest.onreadystatechange=getresultValue; xmlhttprequest.open("post",url,true); xmlhttprequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttprequest.send(userinfo); } //回调方法 function getresultValue(){ if(xmlhttprequest.readyState==4 && xmlhttprequest.status==200){ var result=xmlhttprequest.responseText; if(result=="success"){ window.location.href="index.jsp" rel="external nofollow" ; } else { document.getElementById("xiaoxi").innerHTML="登录失败!"; } } } //页面的按键事件,即当按的是回车键时触发该事件 function keybutton(){ if(event.keyCode==13){ doStart(); return; } } </script>

【使用Ajax技术通过XMLHttpRequest对象完成首页登录功能】相关文章:

Ajax标签导航效果(仿网易首页)

使用jquery 的ajax调用总是错误亲测的解决方法

django使用ajax post数据出现403错误如何解决

ajax技术制作得在线歌词搜索功能

建立XMLHttpRequest对象

Ajax通讯原理XMLHttpRequest

MVC中基于Ajax和HTML5实现文件上传功能

Ajax+smarty技术实现无刷新分页

AJAX客户端说明,XMLHttpRequest对象

解析ajax核心XMLHTTPRequest对象的创建与浏览器的兼容问题

精品推荐
分类导航