How to use ajax technology to complete the home login function through XMLHttpRequest object
本篇内容主要讲解"如何使用ajax技术通过XMLHttpRequest对象完成首页登录功能",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何使用ajax技术通过XMLHttpRequest对象完成首页登录功能"吧!
代码如下:
//创建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")[xss_clean]="登录失败!";}}}//页面的按键事件,即当按的是回车键时触发该事件function keybutton(){if(event.keyCode==13){ doStart(); return;} }到此,相信大家对"如何使用ajax技术通过XMLHttpRequest对象完成首页登录功能"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!