本篇内容主要讲解“如何使用ajax技术通过XMLHttpRequest对象完成首页登录功能”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用ajax技术通过
本篇内容主要讲解“如何使用ajax技术通过XMLHttpRequest对象完成首页登录功能”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用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对象完成首页登录功能”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
--结束END--
本文标题: 如何使用ajax技术通过XMLHttpRequest对象完成首页登录功能
本文链接: https://www.lsjlt.com/news/82241.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0