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