asp.net AJAX實(shí)現(xiàn)無刷新獲得數(shù)據(jù)
更新時間:2008年11月25日 10:07:36 作者:
提供一個使用AJAX實(shí)現(xiàn)無刷新判斷注冊用戶名是否被注冊的代碼:
register.aspx頁面代碼:
<script type="text/javascript">
function checkuser()
{
var option={
parameters:"userid="+$("userid").value,
method:"post",
onSuccess:function(transport){
var rp=transport.responseText;
if(rp=="true")
{
alert("該用戶昵稱存在!!");
}
else
{
alert("該用戶昵稱不存在,請重新輸入!!");
}
},
onFailure:function(transport){
alert("數(shù)據(jù)提交失敗,請檢查網(wǎng)絡(luò)或重試。");
}
}
var request=new Ajax.Request("Ajax.aspx?userid="+escape($("userid").value),option);
}
</script>
昵稱:<asp:TextBox ID="userid" runat="server" Text="" onblur="checkuser()"></asp:TextBox>
Ajax.aspx頁面代碼:
private void Page_Load(object sender, System.EventArgs e)
{
string userid = Request.QueryString["userid"];
string sql = "select userid from blog_user where userid='" + userid + "')";
object o = dbconn.ExecuteScalar(sql);
if (o == null)
Response.Write("false");
else
Response.Write("true");
}
<script type="text/javascript">
function checkuser()
{
var option={
parameters:"userid="+$("userid").value,
method:"post",
onSuccess:function(transport){
var rp=transport.responseText;
if(rp=="true")
{
alert("該用戶昵稱存在!!");
}
else
{
alert("該用戶昵稱不存在,請重新輸入!!");
}
},
onFailure:function(transport){
alert("數(shù)據(jù)提交失敗,請檢查網(wǎng)絡(luò)或重試。");
}
}
var request=new Ajax.Request("Ajax.aspx?userid="+escape($("userid").value),option);
}
</script>
昵稱:<asp:TextBox ID="userid" runat="server" Text="" onblur="checkuser()"></asp:TextBox>
Ajax.aspx頁面代碼:
private void Page_Load(object sender, System.EventArgs e)
{
string userid = Request.QueryString["userid"];
string sql = "select userid from blog_user where userid='" + userid + "')";
object o = dbconn.ExecuteScalar(sql);
if (o == null)
Response.Write("false");
else
Response.Write("true");
}
相關(guān)文章
asp.net DbProviderFactory的使用-示例
NET 2.0有一個抽象工廠模式的典型應(yīng)用:通過DBProviderFactory 可以對不同數(shù)據(jù)庫進(jìn)行操作。2009-11-11
c# 操作符?? null coalescing operator
?? "null coalescing" operator 是c#新提供的一個操作符,這個操作符提供的功能是判斷左側(cè)的操作數(shù)是否是null,如果是則返回結(jié)果是右側(cè)的操作數(shù);非null則返回左側(cè)的操作數(shù)。2009-06-06
如何在ASP.Net Core中使用 IHostedService的方法
這篇文章主要介紹了如何在ASP.Net Core中使用 IHostedService的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件分享
這篇文章介紹了,C#調(diào)用動態(tài)unlha32.dll解壓Lha后綴的打包文件,有需要的朋友可以參考一下2013-09-09
在應(yīng)用程序級別之外使用注冊為allowDefinition=''MachineToApplication''的節(jié)是錯誤的
在應(yīng)用程序級別之外使用注冊為 allowDefinition='MachineToApplication' 的節(jié)是錯誤的2009-03-03
.Net Core路由處理的知識點(diǎn)與方法總結(jié)
這篇文章主要給大家介紹了關(guān)于.Net Core路由處理的知識點(diǎn)與方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04

