代码如下:
// 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)
}
下面代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using LHB_SQL_2005;
public partial class userControl_logon : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(userControl_logon));
}
}
[AjaxPro.AjaxMethod]
public static string checkCodeOperaotr()
{
string _checkCode = GeneralMethod.GenerateCheckCode();
System.Web.HttpContext.Current.Session["checkCode"] = _checkCode;
//返回验证码
return _checkCode;
}
/// <summary>
/// 判断验证是否正确
/// </summary>
/// <param name="checkCode"></param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public static bool CheckCodeIsRight(string checkCode)
{
string _checkCode = (string)(System.Web.HttpContext.Current.Session["checkCode"]);
if (_checkCode == checkCode)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 判断用户名及密码添加是否正确
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="_password">用户名密码</param>
/// <returns>bool</returns>
[AjaxPro.AjaxMethod]
public static bool userNameAndPasswordIsExist(string userName, string _password)
{
string password = GeneralMethod.ToEncryptPassword(_password);
string executeString = "SELECT COUNT(*) FROM users WHERE userName = '" + userName.ToString() + "' AND password = '" + password + "'";
int count = int.Parse(GetCommand.ExecuteScalar(executeString));
if (count == 1)
{
System.Web.HttpContext.Current.Session["userName"] = userName;
return true;
}
else
{
return false;
}
}
/// <summary>
/// 判断用户是不是有这进入管理留言版的权限
/// </summary>
/// <param name="userName">用户名</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public static bool userNameIsRight(string userName)
{
string executeString = "SELECT [right] FROM role WHERE usersId = (select userNameId from users where userName = '" + userName + "')";
int count = int.Parse(GetCommand.ExecuteScalar(executeString));
if (count > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 返回Url值
/// </summary>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public static string returnUrl()
{
string url = "";
try
{
url = System.Web.HttpContext.Current.Session["url"].ToString();
}
catch
{
url ="404";
}
return url;
}
}
下面是页面代码
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="logon.ascx.cs" Inherits="userControl_logon" %> <script language="javascript" type="text/javascript" src="/UploadFiles/2021-04-02/logon.js">以上所述是小编给大家介绍的基于Ajax技术实现无刷新用户登录功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“基于Ajax技术实现无刷新用户登录功能”评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。