Ajax XMLHttpRequest 使用Ajax技术通过XMLHttpRequest对象完成首页登录功能

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Ajax XMLHttpRequest 使用Ajax技术通过XMLHttpRequest对象完成首页登录功能

  2021-03-19 我要评论
想了解使用Ajax技术通过XMLHttpRequest对象完成首页登录功能的相关内容吗,在本文为您仔细讲解Ajax XMLHttpRequest的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们