樣本講解Ajax郵箱、使用者名稱唯一性驗證方法

來源:互聯網
上載者:User
大家對Ajax郵箱、使用者名稱驗證掌握多少呢?本文主要介紹了Ajax郵箱、使用者名稱唯一性驗證執行個體代碼,需要的朋友可以參考下,希望能協助到大家。

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:


 <script type="text/javascript">    $(function () {       $("#txtEmail").blur(function () {        $.ajax({          type: "post",          url: "reg.ashx?email=" + $.trim($("#txtEmail").val()) + "&d=" + (+new Date()),          success: function (data) {            var vCount = parseInt(data);            if (vCount == 0) {              alert("郵箱可以使用");            }            else {              alert("郵箱已經被佔用");            }          }        });      });      $("#checkpwd").blur(function () {        return CheckPwd();      });    });    function CheckPwd()    {      var bCheck = true;      if ($.trim($("#pwd").val()) != $.trim($("#checkpwd").val()))      {        alert("兩次密碼輸入不一致");        bCheck = false;      }      return bCheck;    }  </script>

reg.ashx代碼:


using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace WebT1.Ti.html2{  /// <summary>  /// reg 的摘要說明  /// </summary>  public class reg : IHttpHandler  {    public void ProcessRequest(HttpContext context)    {      if (context.Request["email"] != null)      {        string strEmail = context.Request["email"];        List<UserModel> lstUser = DataService.GetUserList();        var v = lstUser.Where(p => p.Email == strEmail);        int iCount = 0;        if (v.Count() > 0)        {          iCount = 1;        }        context.Response.ContentType = "text/plain";        context.Response.Write(iCount.ToString());      }    }    public bool IsReusable    {      get      {        return false;      }    }  }  public class DataService  {    /// <summary>    /// 類比登入使用者資料    /// </summary>    public static List<UserModel> GetUserList()    {      var list = new List<UserModel>();      list.Add(new UserModel() { Email = "t1@demo.com" });      list.Add(new UserModel() { Email = "t2@demo.com" });      list.Add(new UserModel() { Email = "t3@demo.com" });      list.Add(new UserModel() { Email = "t4@demo.com" });      list.Add(new UserModel() { Email = "t5@demo.com" });      return list;    }  }  public class UserModel  {    public string Email { get; set; }  }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.