Asp.net下利用Jquery Ajax實現(xiàn)用戶注冊檢測(驗證用戶名是否存)
更新時間:2010年09月12日 13:31:46 作者:
最近在朋友做個網站http://www.smarteas.net/,其中用實現(xiàn)用戶注冊這功能,最近網站做到了尾聲,我也就把其它有些技術和大家分享一下。
其中用到了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("服務器沒有返回數(shù)據(jù),可能服務器忙,請重試");},
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ā)這樣的技術文檔,難免有不足之外,還請大家見涼...
下面將提供下載

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("服務器沒有返回數(shù)據(jù),可能服務器忙,請重試");},
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ā)這樣的技術文檔,難免有不足之外,還請大家見涼...
下面將提供下載
相關文章
基于Jquery的將DropDownlist的選中值賦給label的實現(xiàn)代碼
使用Jquery 將DropDownlist的選中值賦給label的代碼,需要的朋友可以參考下。2011-05-05
Jquery操作下拉框(DropDownList)實現(xiàn)取值賦值
Jquery操作下拉框(DropDownList)想必大家都有所接觸吧,下面與大家分享下對DropDownList進行取值賦值的實現(xiàn)代碼2013-08-08
關于jquery.validate1.9.0前臺驗證的使用介紹
本篇文章介紹了,關于jquery.validate1.9.0前臺驗證的使用。需要的朋友參考下2013-04-04

