日期:2014-05-16  浏览次数:20652 次

一个简单的AJAX例子
xml 代码
  1. <!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Strict//EN" ??
  2. ??"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">??
  3. <html?xmlns="http://www.w3.org/1999/xhtml">??
  4. <head>??
  5. <title>Simple?XMLHttpRequest</title>??
  6. ??? ??
  7. <script?type="text/javascript">??
  8. var?xmlHttp; ??
  9. ??
  10. function?createXMLHttpRequest()?{ ??
  11. ????if?(window.ActiveXObject)?{ ??
  12. ????????xmlHttp?=?new?ActiveXObject("Microsoft.XMLHTTP"); ??
  13. ????} ??
  14. ????else?if?(window.XMLHttpRequest)?{ ??
  15. ????????xmlHttp?=?new?XMLHttpRequest(); ??
  16. ????} ??
  17. } ??
  18. ??? ??
  19. function?startRequest()?{ ??
  20. ????createXMLHttpRequest(); ??
  21. ????xmlHttp.onreadystatechange?=?handleStateChange; ??
  22. ????xmlHttp.open("GET",?"simpleResponse.xml",?true); ??
  23. ????xmlHttp.send(null); ??
  24. } ??
  25. ??? ??
  26. function?handleStateChange()?{ ??
  27. ????if(xmlHttp.readyState?==?4)?{ ??
  28. ????????if(xmlHttp.status?==?200)?{ ??
  29. ????????????alert("The?server?replied?with:?"?+?xmlHttp.responseText); ??
  30. ????????} ??
  31. ??
  32. } ??
  33. } ??
  34. </script>??
  35. </head>??
  36. ??
  37. <body>??
  38. ????<form?action=