[JavaScript] JS代码创建一个代码回调函数的XMLHttpRequest从文本文件检索数据 →→→→→进入此内容的聊天室

来自 , 2020-09-04, 写在 JavaScript, 查看 157 次.
URL http://www.code666.cn/view/e2db7186
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. var xmlhttp;
  6. function loadXMLDoc(url,cfunc)
  7. {
  8. if (window.XMLHttpRequest)
  9.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  10.   xmlhttp=new XMLHttpRequest();
  11.   }
  12. else
  13.   {// code for IE6, IE5
  14.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  15.   }
  16. xmlhttp.onreadystatechange=cfunc;
  17. xmlhttp.open("GET",url,true);
  18. xmlhttp.send();
  19. }
  20. function myFunction()
  21. {
  22. loadXMLDoc("ajax_info.txt",function()
  23.   {
  24.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  25.     {
  26.     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  27.     }
  28.   });
  29. }
  30. </script>
  31. </head>
  32. <body>
  33.  
  34. <div id="myDiv"><h2>Let AJAX change this text</h2></div>
  35. <button type="button" onclick="myFunction()">Change Content</button>
  36.  
  37. </body>
  38. </html>
  39.  
  40. //javascript/8184

回复 "JS代码创建一个代码回调函数的XMLHttpRequest从文本文件检索数据"

这儿你可以回复上面这条便签

captcha