手机
当前位置:查字典教程网 >编程开发 >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获取XMLHttp对象的方法

Ajax核心XMLHTTP组件资料第1/2页

使用ajax技术实现txt弹出在页面上的方法

使用ajax操作JavaScript 对象详解

使用ajax技术无刷新动态调用股票信息

Django框架利用ajax实现批量导入数据功能

AJAX客户端说明,XMLHttpRequest对象

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

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

AJax 学习笔记一(XMLHTTPRequest对象)

精品推荐
分类导航