Ajax郵箱、用戶名唯一性驗(yàn)證實(shí)例代碼
廢話不多說(shuō)了,直接給大家貼代碼了,具體代碼如下所示:
<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 的摘要說(shuō)明
/// </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>
/// 模擬已注冊(cè)用戶數(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í)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
基于HTML5 Ajax實(shí)現(xiàn)文件上傳并顯示進(jìn)度條
這篇文章主要介紹了基于HTML5 Ajax實(shí)現(xiàn)文件上傳并顯示進(jìn)度條的相關(guān)資料,需要的朋友可以參考下2016-02-02
jQuery中ajax - get() 方法實(shí)例詳解
在JQuery中可以使用get,post和ajax方法給服務(wù)器端傳遞數(shù)據(jù),接下來(lái),通過(guò)本篇文章給大家介紹jquery中ajax-get()方法實(shí)例詳解,有需要的朋友可以參考下2015-09-09
Ajax請(qǐng)求二進(jìn)制流進(jìn)行處理(ajax異步下載文件)的簡(jiǎn)單方法
最近做項(xiàng)目遇到這樣的需求:管理后臺(tái)需要隨時(shí)下載數(shù)據(jù)報(bào)表,數(shù)據(jù)要實(shí)時(shí)生成后轉(zhuǎn)換為excel下載。怎么解決這個(gè)問(wèn)題呢?下面小編給大家分享Ajax請(qǐng)求二進(jìn)制流進(jìn)行處理(ajax異步下載文件)的簡(jiǎn)單方法,一起看看吧2017-09-09
IE瀏覽器與FF瀏覽器關(guān)于Ajax傳遞參數(shù)值為中文時(shí)的區(qū)別實(shí)例分析
這篇文章主要介紹了IE瀏覽器與FF瀏覽器關(guān)于Ajax傳遞參數(shù)值為中文時(shí)的區(qū)別,結(jié)合實(shí)例分析說(shuō)明了ajax參數(shù)傳遞過(guò)程中的參數(shù)轉(zhuǎn)碼相關(guān)注意事項(xiàng)與使用技巧,需要的朋友可以參考下2015-12-12
AJAX分頁(yè)效果簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了AJAX分頁(yè)效果的簡(jiǎn)單實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
AJAX顯示加載中并彈出圖層遮擋頁(yè)面的實(shí)現(xiàn)示例
大家都知道AJAX的請(qǐng)求是異步的,這種異步的機(jī)制給我們帶來(lái)了體驗(yàn)上的優(yōu)化,但是同時(shí)我要求我們有更完善的思維去處理一個(gè)業(yè)務(wù)。當(dāng)用戶請(qǐng)求后長(zhǎng)時(shí)間沒有回應(yīng)是一種非常不好的用戶體驗(yàn),所以我們可以在請(qǐng)求后利用AJAX顯示加載中并彈出圖層遮擋頁(yè)面,下面來(lái)看看實(shí)現(xiàn)方法。2016-12-12
Ajax讀取數(shù)據(jù)之分頁(yè)顯示篇實(shí)現(xiàn)代碼
前幾篇的ajax教程里講了,讀取,添加,修改,刪除的功能.有幾天沒有更新了,雖然網(wǎng)上也有很多ajax分頁(yè)的教程和相關(guān)實(shí)例.2010-10-10

