欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net AJAX实现无刷新获得数据

程序员文章站 2022-08-26 08:21:10
register.aspx页面代码: function checkuser() { var op...
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");
}