1. Chat.html
  2. ---------
  3.  
  4. <html>
  5. <head>
  6. <script type="text/javascript">
  7. function showUser(str)
  8. {
  9. if (str=="")
  10. {
  11. document.getElementById("chat").innerHTML="";
  12. return;
  13. }
  14. if (window.XMLHttpRequest)
  15. {// code for IE7+, Firefox, Chrome, Opera, Safari
  16. xmlhttp=new XMLHttpRequest();
  17. }
  18. else
  19. {// code for IE6, IE5
  20. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  21. }
  22. xmlhttp.onreadystatechange=function()
  23. {
  24. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  25. {
  26. document.getElementById("chat").innerHTML=xmlhttp.responseText;
  27. }
  28. }
  29. xmlhttp.open("GET","chat.php?q="+str,true);
  30. xmlhttp.send();
  31. }
  32. </script>
  33. </head>
  34. <body>
  35.  
  36. <form name="form">
  37. <input type="text" id="text">
  38. <input type='submit' onclick="showUser(document.form.getElementById("text").value)">
  39. </form>
  40.  
  41. <div id="chat">cdffdsfafs</div>
  42.  
  43. </body>
  44. </html>
  45.  
  46. -------
  47. Chat.php
  48. -------
  49. <?php
  50. $response="VLOL";
  51. echo $response;
  52. ?>