Asp.net下利用Jquery Ajax實現(xiàn)用戶注冊檢測(驗證用戶名是否存)
更新時間:2010年09月12日 13:31:46 作者:
最近在朋友做個網(wǎng)站http://www.smarteas.net/,其中用實現(xiàn)用戶注冊這功能,最近網(wǎng)站做到了尾聲,我也就把其它有些技術(shù)和大家分享一下。
其中用到了jquery插件來驗證用戶名哦,這里是利用jquery ajax來驗證用戶名是否存在哦。大家看看效果圖,后面將附上源碼下載。

jquery框架實現(xiàn)的ajax 驗證用戶名是否存在的部分JS
$("#accounts").formValidator({onshow:"請輸入用戶名",onfocus:"用戶名至少4個字符,最多10個字符",oncorrect:"該用戶名可以注冊"}).inputValidator({min:4,max:10,onerror:"用戶名至少4個字符,最多10個字符"}).regexValidator({regexp:"username",datatype:"enum",onerror:"用戶名格式不正確"})
.ajaxValidator({
type : "get",
url : "/ws/NameExist.aspx",
datatype : "json",
success : function(data){
if( data == "1" )
{
return true;
}
else
{
return false;
}
},
buttons: $("#submit"),
error: function(){alert("服務(wù)器沒有返回數(shù)據(jù),可能服務(wù)器忙,請重試");},
onerror : "該用戶名不可用,請更換用戶名",
onwait : "正在對用戶名進行合法性校驗,請稍候..."
})
NameExist.aspx 實現(xiàn)的源碼
protected void Page_Load(object sender, EventArgs e)
{
string accounts = Request["accounts"];
LoginNameExist(accounts);
}
public void LoginNameExist(string accounts)
{
IUsers user = AgileEIS.Web.DAL.Interface.DALHelper.DALManager.CreateUsers();
user.Session = ContextHelper.Session;
user.Accounts = accounts;
user.Refresh();
if (!user.Exists)
{
Response.Write("1");
}
else
{
Response.Write("0");
}
Response.End();
return;
}
異步刷新實現(xiàn)方式有多種,也可以借助js的多種框架,以上是使用jquery框架實現(xiàn)的ajax 驗證用戶名是否存在。首次發(fā)這樣的技術(shù)文檔,難免有不足之外,還請大家見涼...
下面將提供下載

jquery框架實現(xiàn)的ajax 驗證用戶名是否存在的部分JS
復制代碼 代碼如下:
$("#accounts").formValidator({onshow:"請輸入用戶名",onfocus:"用戶名至少4個字符,最多10個字符",oncorrect:"該用戶名可以注冊"}).inputValidator({min:4,max:10,onerror:"用戶名至少4個字符,最多10個字符"}).regexValidator({regexp:"username",datatype:"enum",onerror:"用戶名格式不正確"})
.ajaxValidator({
type : "get",
url : "/ws/NameExist.aspx",
datatype : "json",
success : function(data){
if( data == "1" )
{
return true;
}
else
{
return false;
}
},
buttons: $("#submit"),
error: function(){alert("服務(wù)器沒有返回數(shù)據(jù),可能服務(wù)器忙,請重試");},
onerror : "該用戶名不可用,請更換用戶名",
onwait : "正在對用戶名進行合法性校驗,請稍候..."
})
NameExist.aspx 實現(xiàn)的源碼
復制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
string accounts = Request["accounts"];
LoginNameExist(accounts);
}
public void LoginNameExist(string accounts)
{
IUsers user = AgileEIS.Web.DAL.Interface.DALHelper.DALManager.CreateUsers();
user.Session = ContextHelper.Session;
user.Accounts = accounts;
user.Refresh();
if (!user.Exists)
{
Response.Write("1");
}
else
{
Response.Write("0");
}
Response.End();
return;
}
異步刷新實現(xiàn)方式有多種,也可以借助js的多種框架,以上是使用jquery框架實現(xiàn)的ajax 驗證用戶名是否存在。首次發(fā)這樣的技術(shù)文檔,難免有不足之外,還請大家見涼...
下面將提供下載
相關(guān)文章
有關(guān)jquery與DOM節(jié)點操作方法和屬性記錄
下面小編就為大家?guī)硪黄嘘P(guān)jquery與DOM節(jié)點操作方法和屬性記錄。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考2016-04-04一個可以增加和刪除行的table并可編輯表格中內(nèi)容
本例要實現(xiàn)的是一個可以增加和刪除行的table并可編輯表格中內(nèi)容,適合新手朋友2014-06-06jQuery實現(xiàn)統(tǒng)計輸入文字個數(shù)的方法
這篇文章主要介紹了jQuery實現(xiàn)統(tǒng)計輸入文字個數(shù)的方法,涉及jQuery操作鼠標事件及dom元素的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03