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("數據提交失敗,請檢查網絡或重試。");
}
}
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");
}