Ajax (User Registration)

Source: Internet
Author: User

HTML code:

  1. <Head>
  2. <SCRIPT type = "text/JavaScript">
  3. VaR XMLHTTP;
  4. Function createxmlhttprequest ()
  5. {
  6. If (window. XMLHttpRequest)
  7. {
  8. XMLHTTP = new XMLHttpRequest (); // Mozilla Browser
  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 ("You cannot create an XMLHTTP object instance! ");
  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 = "registrable ";
  45. }
  46. Else
  47. {
  48. Document. getelementbyid ('check'). innertext = "cannot be registered ";
  49. }
  50. }
  51. }
  52. }
  53. </SCRIPT>
  54. </Head>
  55. <Body>
  56. Username: <input id = "username" type = "text" onkeyup = "checkname (document. getelementbyid ('username'). Value);">
  57. <Div id = "check"> </div>
  58. </Body>

 

  1. Dispost. aspx background code:

  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. }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.