为什么xmlHttp.responseXML为空??????????????????????
这是 parseXML.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<states>
<north>
<state>Minnesota</state>
<state>Iowa</state>
<state>North Dakota</state>
</north>
<south>
<state>Texas</state>
<state>Oklahoma</state>
<state>Louisiana</state>
</south>
<east>
<state>New York</state>
<state>North Carolina</state>
<state>Massachusetts</state>
</east>
<west>
<state>california</state>
<state>oREGOn</state>
<state>Nevada</state>
</west>
</states>
这是html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xml; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script type=text/javascript>
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function startRequest(requestedList)
{
requestType=requestedList;
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET","parseXML.xml",true);
xmlHttp.send(null);
}
function handleStateChange()
{
if(xmlHttp.readyState==4)
{
if(requestType=="north")
{
listNorthStates();
}
else if(requestType=="all")
{
listAllstatus();
}
}
}
function listNorthStates()
{
var xmlDoc=xmlHttp.responseXML;
var northNode=xmlDoc.getElementsByTagName("states")[0];
var out="Northern States";
var northStates=northNode.getElementsByTagName("state");
outputList("Northern States",northStates);
}
function listAllstatus()
{
var xmlDoc=xmlHttp.responseXML;
var allStates=xmlDoc.getElementsByTagName("state");
outputList("All States in Document",allStates);
}
function outputList(title,states)
{
var out=title;
var currentState=null;
for(var i=0;i<states.length;i++)
{
currentState=states[i];
out=out+"\n-"+currentState.childNodes[0].nodeValue;
}
alert(out);
}
</script>
<body>
<h1>Process XML Document of U.S.States</h1>
<br>
<br>
<form>
<input type="button" value="View All List states" onclick="startRequest('all');"/>
<input type="button" value="View All Listed Northern states" onclick="startRequest('north');"/>
</form>
</body>
</html>
为什么 northNode=xmlDoc.getElementsByTagName("states")[0];总是取不到值而我
用alert(xmlHttp.responseText) 却能得到