我通过Ajax将一些XML从PHP返回到Javascript,但得到“无效的XML”错误提示。返回的XML如下所示:
<response>
<song>tdb2009-01-29s2s06</song>
<song>tdb2009-01-29s1s02</song>
</response>
解析它的javascript如下所示:
function u_handleServerResponse(){
//pull xml from xml response
var xmlResponse = xmlHttp.responseXML;
//check to see if xml was pulled
if(!xmlResponse || !xmlResponse.documentElement){
throw("Invalid XML Structure:
" + xmlHttp.responseText);
}
//this is for catching errors with firefox
var rootNodeName = xmlResponse.documentElement.nodeName;
//check for errors
if(rootNodeName == "parsererror"){
throw("Invalid XML Strucutre");
}
//get the root
xmlRoot = xmlResponse.documentElement;
var songArray = xmlRoot.getElementsByTagName("song");
for(var i = 0; i < songArray.length; i++){
etc., etc...
得到的错误如下:
Error reading the response: Invalid XML Strucutre
你觉得这是对的吗?XML本身是错的还是加载错了?我们非常感谢所有的帮助。