似乎我的JavaScript沒有拿起我的PHP發回一個XML文檔。 PHP代碼:以上Javascript無法解釋返回的xml
$domtree = new DOMDocument('1.0', 'UTF-8');
/* append it to the document created */
$xmlRoot = $domtree->appendChild($domtree->createElement("root"));
foreach (glob('./img/photos/*.*') as $filename) {
//echo $filename;
$xmlRoot->appendChild($domtree->createElement("image",$filename));
}
/* get the xml printed */
echo $domtree->saveXML();
代碼的輸出結果如下:
<?xml version="1.0" encoding="UTF-8"?>
<root><image>./img/photos/2012-02-26 17.02.12.jpg</image>
<image>./img/photos/2012-03-09 08.21.48.jpg</image>
<image>./img/photos/2012-07-21 14.09.39.jpg</image>
<image>./img/photos/2012-07-25 15.25.17.jpg</image>
<image>./img/photos/2012-08-04 17.54.38.jpg</image>
<image>./img/photos/2012-08-04 23.36.30.jpg</image>
<image>./img/photos/2012-08-06 06.08.43.jpg</image>
<image>./img/photos/2012-08-07 20.57.34.jpg</image>
<image>./img/photos/2012-08-09 20.40.11.jpg</image>
<image>./img/photos/2012-08-25 20.54.05.jpg</image>
<image>./img/photos/2012-09-07 11.19.50.jpg</image>
<image>./img/photos/2012-09-08 15.53.27.jpg</image>
<image>./img/photos/2013-01-30 19.19.16.jpg</image>
<image>./img/photos/2013-01-31 09.48.39.jpg</image></root>
與AJAX調用這個,當我打電話AJAXRequest.responseXML我得空回來。
編輯:AJAX請求代碼:
什麼是AJAX代碼?也直接調用它回寫什麼是PHP的輸出,所以我們可以看到什麼JavaScript試圖解析。 – PhoneixS
查看答案[here](http://stackoverflow.com/questions/1013582/ajax-responsexml-errors) – 2013-04-03 16:07:58
您的PHP腳本是否返回了正確的「Content-Type」標頭?有關更多信息,請參見http://stackoverflow.com/a/3272572/156755 – Basic