我使用JavaScript(客户端)试图从具有XML内容(服务器端)PHP页面得到的responseXML发送的XMLHttpRequest我不能。当html页面和php页面处于同一级别时(本地主机),我没有任何问题。当问题不存在时,问题就会开始 - responseXML始终为空。responseXML的使用AJAX(XMLHttpRequest的)
奇怪的是,我得到这个结果使用不同的浏览器(铬,火狐,歌剧)除IE8这是给我正确的responseText(而不是responseXML),但只有我“允许阻止的内容”后。
另一件事。我使用phonegap将这个html页面(请求页面)转换为一个Android应用程序(这是我的主要目标),当我在我的平板电脑上测试应用程序时,我得到了相同的结果(空响应)。下面是客户端代码:
<html>
<head>
<title> T_d test </title>
<script language="javascript">
var infoPage="http://172.25.10.215/list2.php";
// 172.25.10.215 the IP address of the server
function test()
{
var xht = new XMLHttpRequest();
xht.open("GET",infoPage,true);
xht.send();
xht.onreadystatechange=function() {
if (xht.readyState==4) {
alert(""+xht.responseXML);
document.getElementById("id1").innerHTML="The result is : "+xht.responseText;
}
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
btn
<input name="btn" type="button" id="btn" onClick="test();" value="Submit" />
</form>
<label id="id1"></label>
</body>
</html>
这里是服务器页面代码:
<?php
header('Content-Type: text/xml');
?>
<root>
<file>
<filename>Test.txt</filename>
<fileCreatingDate>15-7-2013</fileCreatingDate>
<fileModifyDate>20-7-2013</fileModifyDate>
<filesize>10002345</filesize>
<filetype> Text</filetype>
</file>
<file>
<filename>Test2.txt</filename>
<fileCreatingDate>19-7-2013</fileCreatingDate>
<fileModifyDate>20-8-2013</fileModifyDate>
<filesize>3002345</filesize>
<filetype> Text</filetype>
</file>
</root>
这里是我开始使用IE8响应文本:
结果是:Test.txt的15-7-2013 20-7-2013 10002345 Text Test2.txt 19-7-2013 20-8-2013 3002345 Text
Could y你请帮忙? 感谢
都是在同一台服务器上的文件? –
您可能还需要检查'xht.status'是'200' – Ian