刚开始写AJAX代码的时候,直接参照的是AJAX基础教程一书中的代码(该书真的很不错,是AJAX入门的经典教材,是图灵出版社的。计算机方面的书籍,我最信任的就是O'R和图灵的)。

该书的创建XMLHttpRequest对象的代码如下:

01 var xmlHttp;
02   
03 function createXMLHttpRequest()
04 {
05     if (window.ActiveXObject)
06     {
07         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
08     }
09     else if (window.XMLHttpRequest)
10     {
11         xmlHttp = new XMLHttpRequest();
12     }
13 }

在一般情况下,该代码的使用不会带来任何问题。

如:

01 function test1()
02 {
03     createXMLHttpRequest();
04     xmlHttp.onreadystatechange = handleStateChange1;
05     url = "test.php?ts=" + new Date().getTime();
06     xmlHttp.open("GET", url, true);
07     xmlHttp.send(null);
08 }
09   
10 function test2()
11

相关文章:

  • 2021-06-26
  • 2021-11-11
  • 2021-07-15
  • 2021-12-05
  • 2021-10-22
  • 2021-04-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案