首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

一个容易的AJAX例子

2012-11-09 
一个简单的AJAX例子??http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd??html?xmlnshttp://www.w

一个简单的AJAX例子

    ??"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">??
  1. <html?xmlns="http://www.w3.org/1999/xhtml">??
  2. <head>??
  3. <title>Simple?XMLHttpRequest</title>??
  4. ??? ??
  5. <script?type="text/javascript">??
  6. var?xmlHttp; ??
  7. ??
  8. function?createXMLHttpRequest()?{ ??
  9. ????if?(window.ActiveXObject)?{ ??
  10. ????????xmlHttp?=?new?ActiveXObject("Microsoft.XMLHTTP"); ??
  11. ????} ??
  12. ????else?if?(window.XMLHttpRequest)?{ ??
  13. ????????xmlHttp?=?new?XMLHttpRequest(); ??
  14. ????} ??
  15. } ??
  16. ??? ??
  17. function?startRequest()?{ ??
  18. ????createXMLHttpRequest(); ??
  19. ????xmlHttp.onreadystatechange?=?handleStateChange; ??
  20. ????xmlHttp.open("GET",?"simpleResponse.xml",?true); ??
  21. ????xmlHttp.send(null); ??
  22. } ??
  23. ??? ??
  24. function?handleStateChange()?{ ??
  25. ????if(xmlHttp.readyState?==?4)?{ ??
  26. ????????if(xmlHttp.status?==?200)?{ ??
  27. ????????????alert("The?server?replied?with:?"?+?xmlHttp.responseText); ??
  28. ????????} ??
  29. ??
  30. } ??
  31. } ??
  32. </script>??
  33. </head>??
  34. ??
  35. <body>??
  36. ????<form?action="#">??
  37. ????????<input?type="button"?value="Start?Basic?Asynchronous?Request"?onclick="startRequest();"/>??
  38. ????</form>??
  39. </body>??
  40. </html>??
  41. ??
  42. 所用到的xml文件 ??
  43. ??
  44. simpleResponse.xml//放在同一个目录下就可以了 ??
  45. ??
  46. Hello?from?the?server! ??
  47. ? ??

热点排行