ajax(使用者註冊)

來源:互聯網
上載者:User

 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" onkeyup="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. }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.