国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > AJAX > 正文

基于Ajax技術實現無刷新用戶登錄功能

2024-09-01 08:27:31
字體:
來源:轉載
供稿:網友

代碼如下:

// 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;  }}            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 淅川县| 丘北县| 正安县| 蓝田县| 金塔县| 石泉县| 郯城县| 庆城县| 门头沟区| 沙雅县| 广平县| 东山县| 文成县| 钟祥市| 湖南省| 海盐县| 雷山县| 济阳县| 手游| 张掖市| 淄博市| 仁寿县| 京山县| 类乌齐县| 余姚市| 启东市| 天门市| 祁连县| 隆尧县| 海原县| 西宁市| 出国| 阿合奇县| 盐亭县| 长乐市| 贵溪市| 新邵县| 静宁县| 大理市| 阿巴嘎旗| 滨州市|