基于Ajax技术实现无刷新用户登录功能,ajax用户登录
代码如下:
// JScript 文件 function usersLogon() { var userName = document.getElementById("txtuserName").value; var password = document.getElementById("txtpassword").value; var checkCode = document.getElementById("txtCheckCode").value; var response = userControl_logon.CheckCodeIsRight(checkCode).value; if(userName == "") { document.getElementById("txtuserName").focus(); return false; } else if(password == "") { document.getElementById("txtpassword").focus(); return false; } else if(checkCode =="") { document.getElementById("txtCheckCode").focus(); return false; } else { if(response == true) { //判断用户是否存在 userControl_logon.userNameAndPasswordIsExist(userName,password,userNameIsRight); } else { alert("验证码出错"); userControl_logon.checkCodeOperaotr(refreshCheckCode); document.getElementById("txtpassword").value = ""; } } } function userNameIsRight(res) { var userName = document.getElementById("txtuserName").value; if(res.value == true) { //用户存在,但要看此用户有没有进入管理留言版权限, userControl_logon.userNameIsRight(userName,CallBack); } else { alert("用户名或密码错误"); document.getElementById("txtpassword").value = ""; OnLoad_checkCode(); } } function CallBack(res) { if(res.value == true) { hideLogon(); var url = userControl_logon.returnUrl(); if ( url.value == 404) { showDefault(); } else { document.getElementById("Url").innerHTML = '<a href="' + url.value + '">' + url.value + '</a>' } } else { alert("对不起你的权限不够"); document.getElementById("txtpassword").value = ""; OnLoad_checkCode(); } } //隐藏登录框 function hideLogon() { var element = document.getElementById("hideLogon") element.style.display = "none" } //显示返回首页 function showDefault() { var element = document.getElementById("Returndefault") element.style.display = "block" } function OnLoad_checkCode() { userControl_logon.checkCodeOperaotr(refreshCheckCode); document.getElementById("txtuserName").focus(); // return false; } ///重新得到新的验证吗 function refreshCheckCode(res) { document.getElementById("txtCheckCode").value = ""; document.getElementById("lblNumber").innerHTML = res.value; } function abce() { alert(document.getElementById("lblNumber").value) }下面代码
下面是页面代码
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="logon.ascx.cs" Inherits="userControl_logon" %> <script language="javascript" type="text/javascript" src="../JavaScript/logon.js"> </script> <script language="javascript" type="text/javascript" src="JavaScript/logon.js"> </script> <link href="../CSS/table_css.css" type="text/css" /> <link href="CSS/table_css.css" type="text/css" /> <body> <div> <table cellpadding="0" cellspacing="0"> <tr> <td> <table cellpadding="0" cellspacing="0"> <tr> <td>用户名:</td> <td><input type="text" /></td> </tr> <tr> <td>密 码:</td> <td> <input type="password" /></td> </tr> <tr> <td>验证码:</td> <td> <input type= "text" /><label></label></td> </tr> <tr> <td></td> <td> <input type="button" value="登录" /></td> </tr> </table> </td> </tr> <tr> <td > <div></div> </td> </tr> <tr> <td> <table cellpadding="0" cellspacing="0"> <tr> <td> <asp:HyperLink runat="server" NavigateUrl="~/Default.aspx">返回首页</asp:HyperLink></td> </tr> </table> </td> </tr> </table> </div> </body>以上所述是小编给大家介绍的基于Ajax技术实现无刷新用户登录功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对帮客之家网站的支持!