responseXML不能使用。 - Web 开发 / Ajax
现在建了如下两个文件,问题见注释部分
html文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
     <title>Untitled Page</title>
</head>
<body>
<script language="javascript" type="text/javascript">
     var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	xmlRequest.onreadystatechange=stateChange;
	xmlRequest.open("GET","books.xml");
	xmlRequest.send();
	function stateChange()
	{
	   if(xmlRequest.readyState==4)
            {
              //if(xmlRequest.status ==200)     //问题一,为什么加上这一行代码后,连responseText都不能使用了?
	     //{
	          var xmlDOC=xmlRequest.responseXML;               //这三行代码为什么读不出来结果?用responseText是可以读文件的。
	          var books= xmlDOC.getElementByTagName("book");   //
	          alert(books[0].childNodes[0].nodeValue);         //
	     //}
	    }
	}
</script>
</body>
</html>
XML文件
<?xml version="1.0" encoding="utf-8"?>
<books>
     <book>c#</book>
     <book>spring</book>
     <book>AA</book>
</books>
------解决方案--------------------测试ajax一定要在建立iis服务下进行
直接双击html文件是没有效果的!!
------解决方案--------------------没仔细看,你代码有错,少了s
你安装了iis没有??上面的代码肯定是可以运行的
而且你的代码只能在ie下运行,没办法在ff下运行
var   books=   xmlDOC.getElementByTagName( "book ");   
==>var   books=   xmlDOC.getElement
sByTagName( "book ");