重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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

本篇内容主要讲解“如何使用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").innerHTML="登录失败!";

}

}

}

//页面的按键事件,即当按的是回车键时触发该事件

function keybutton(){

if(event.keyCode==13){ 
doStart(); 
return;
} 
}

到此,相信大家对“如何使用ajax技术通过XMLHttpRequest对象完成首页登录功能”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


网站名称:如何使用ajax技术通过XMLHttpRequest对象完成首页登录功能
本文链接:http://cqcxhl.com/article/gshesi.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP