ajax(用户注册)

 html代码:

  1. <head>
  2. <script type="text/javascript">
  3.         var xmlHttp;
  4.         function createXMLHttpRequest()
  5.         {
  6.             if(window.XMLHttpRequest)
  7.             {
  8.               xmlHttp = new XMLHttpRequest();//mozilla浏览器
  9.             }
  10.             else if(window.ActiveXObject)
  11.             {
  12.                try
  13.                {
  14.                 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  15.                }
  16.                catch(e){}
  17.                try
  18.                {
  19.                 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  20.                }
  21.                catch(e){}
  22.                if (!xmlHttp)
  23.                {
  24.                    alert("不能创建xmlHttp对象实例!");
  25.                }
  26.             }
  27.         }
  28.         function CheckName(userName)
  29.         {
  30.             createXMLHttpRequest();
  31.             var url="Dispost.aspx?Name="+userName;
  32.             xmlHttp.onreadystatechange = CheckUserName;
  33.             xmlHttp.open("GET",url,true);
  34.             xmlHttp.send(null);
  35.         }
  36.         function CheckUserName()
  37.         {
  38.             if(xmlHttp.readyState==4)
  39.             {
  40.                 if(xmlHttp.status==200)
  41.                 {
  42.                    if(xmlHttp.responseText=="true")
  43.                     {
  44.                        document.getElementById('check').innerText="可以注册";
  45.                     }
  46.                     else
  47.                      {
  48.                        document.getElementById('check').innerText="不可以注册";
  49.                      }
  50.                 }
  51.             }
  52.         }
  53.     </script>
  54. </head>
  55. <body>
  56.  用户名:<input id="userName" type="text" οnkeyup="CheckName(document.getElementById('userName').value);">
  57. <div id="check"></div>
  58. </body>

 

  1. Dispost.aspx后台代码:
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.  User user=new User();
  4.  if(user.checkName(Resquest.QueryString["Name"].ToString()))
  5.  {
  6.   Response.Write("false");
  7.   Response.End();
  8.  }
  9.  else
  10.  {
  11.  Response.Write("true");
  12.  Response.End();
  13.  }
  14. }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值