+ -
当前位置:首页 → 问答吧 →  w3c的例子有问题?

w3c的例子有问题?

时间:2010-09-10

来源:互联网

<html>
<body>
<script type="text/javascript">
xmlHttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Opera, etc.
  xmlHttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlHttp!=null)
  {
  xmlHttp.open("GET", "advance.xml", false);
  xmlHttp.send(null);
  xmlDoc=xmlHttp.responseText;
  alert(xmlDoc);

// xmlHttp.open("POST", "demo_dom_http.asp", false);
// xmlHttp.send(xmlDoc);
// document.write(xmlHttp.responseText);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
</script>
</body>
</html>

以上的例子是我在W3C上面复制下来的,值注释了3行。但是运行时提示xmlHttp.open("GET", "advance.xml", false);有错。

advance.xml这个文件也有。并且路径也是对的。

作者: blandyzld   发布时间: 2010-09-10

是以http方式测试的吗

作者: net_lover   发布时间: 2010-09-10

http方式?怎么测试?

作者: blandyzld   发布时间: 2010-09-10

就是把你的文件放在站点下测试啊,比如iis,tomcat,而不是
直接点击本地的htm文件

作者: net_lover   发布时间: 2010-09-10

哦!明白了!

作者: blandyzld   发布时间: 2010-09-10

但是这样的话,在本地点击htm文件也可以呀。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<script type="text/javascript">
xmlhttp=null;
if (window.ActiveXObject) 
{
  xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
else if (window.XMLHttpRequest) 
{
  xmlhttp = new XMLHttpRequest();
}

if (xmlhttp==null)
{
  alert("Your browser does not support XMLHTTP.");
}
if (xmlhttp!=null)
  {
  xmlhttp.open("GET", "advance.xml", false);
  xmlhttp.send(null);
  xmlDoc=xmlhttp.responseText;
  alert(xmlDoc);

// xmlHttp.open("POST", "demo_dom_http.asp", false);
// xmlHttp.send(xmlDoc);
// document.write(xmlHttp.responseText);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
</script>
</body>
</html>

不明白为什么?

作者: blandyzld   发布时间: 2010-09-10