Posted By

kangcom on 03/22/11


Tagged

ajax


Versions (?)

Checking of duplicated userid using XMLHTTP (or AJAX)


 / Published in: JavaScript
 

  1. ############################
  2. html file
  3. ############################
  4.  
  5.  
  6. <script language=javascript>
  7.  
  8. var xmlHttp_1 = null;
  9. var objDiv_1 = null;
  10. var htmlContents_1 = null;
  11.  
  12. function createXMLHttpRequest_1() {
  13. if (window.ActiveXObject) {
  14. xmlHttp_1 = new ActiveXObject("Microsoft.XMLHTTP");
  15. }
  16. else if (window.XMLHttpRequest) {
  17. xmlHttp_1 = new XMLHttpRequest();
  18. }
  19. }
  20.  
  21. function handleStateChange_1() {
  22.  
  23. if(xmlHttp_1.readyState == 4) {
  24. if(xmlHttp_1.status == 200) {
  25. htmlContents_1 = xmlHttp_1.responseText;
  26. objDiv_1.innerHTML = htmlContents_1;
  27. }
  28. }
  29. }
  30.  
  31.  
  32.  
  33. function getContents_1(url, divv) {
  34.  
  35. objDiv_1 = document.getElementById(divv);
  36.  
  37. createXMLHttpRequest_1();
  38. xmlHttp_1.onreadystatechange = handleStateChange_1;
  39.  
  40. xmlHttp_1.open("GET", url, true);
  41. xmlHttp_1.send(null);
  42. }
  43.  
  44. function send(name, layer) {
  45. getContents_1("./idchk.php?id="+name,layer);
  46. }
  47.  
  48. </script>
  49.  
  50.  
  51. <form>
  52. <input name=n type=text size=10>
  53. <input type=button value=Input onClick=send(this.form.n.value,'layer1')>
  54. </form>
  55.  
  56. <!-- result -->
  57. <div ID="layer1"></div>
  58.  
  59.  
  60.  
  61. ############################
  62. php file (idchk.php)
  63. ############################
  64.  
  65. <?
  66.  
  67.  
  68. echo "You can use <b>".$_GET['id']."</b>";
  69. ?>

Report this snippet  

You need to login to post a comment.