Ajax郵箱、用戶名唯一性驗(yàn)證實(shí)例代碼
更新時(shí)間:2017年10月26日 10:18:52 作者:my98800
這篇文章主要介紹了Ajax郵箱、用戶名唯一性驗(yàn)證實(shí)例代碼,需要的朋友可以參考下
廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:
<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("郵箱已經(jīng)被占用"); } } }); }); $("#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> /// 模擬已注冊用戶數(shù)據(jù) /// </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; } } }
總結(jié)
以上所述是小編給大家介紹的Ajax郵箱、用戶名唯一性驗(yàn)證實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
解決微信返回上一頁,頁面中的AJAX的請求,對Get請求無效的問題
這篇文章給大家介紹微信返回上一頁,頁面中的AJAX的請求,對Get請求無效的問題分析及解決方法,需要的朋友參考下2017-01-01Ajax注冊用戶時(shí)實(shí)現(xiàn)表單驗(yàn)證
這篇文章主要為大家詳細(xì)介紹了Ajax注冊用戶時(shí)實(shí)現(xiàn)表單驗(yàn)證,在網(wǎng)站上注冊時(shí),通常需要驗(yàn)證用戶名和電子郵件地址的可用性,本文將介紹如何實(shí)現(xiàn)表單驗(yàn)證功能2015-12-12AJAX 二級級聯(lián)菜單實(shí)現(xiàn)代碼
AJAX實(shí)現(xiàn)二級級聯(lián)菜單,用PHP完成2009-11-11