这部分偶也没深研,关注一下。
// 取得<info>结果
var info = root.getElementsByTagName('info');
// 显示返回结果
alert("responseXML's value: " + info[0].firstChild.data);
对于<info></info>
是否会出异常?我记得用nodeValue是会出错的。
// 取得<info>结果
var info = root.getElementsByTagName('info');
// 显示返回结果
alert("responseXML's value: " + info[0].firstChild.data);
对于<info></info>
是否会出异常?我记得用nodeValue是会出错的。
{
var commonurl = url;
if( window.XMLHttpRequest )
commonreq = new XMLHttpRequest();
else if( window.ActiveXObject )
commonreq = new ActiveXObject("Microsoft.XMLHTTP");
if( commonreq )
{
commonreq.open("GET",commonurl, false);
commonreq.send();
var commontxt = commonreq.responseXML;
return commontxt;
}
return null;
}
var obj = commongetResultXML(surl);
if((obj!=null)&&(obj.xml!=""))
{
var id =xmlElement.getElementsByTagName("id");
alert(id);
}
就是这里错了应该是info[0].firstChild.nodeValue才对你试试
服务器端设置
response.setContentType("text/xml;charset=UTF-8");
在IE下取info[0]的值时,firstChild.nodeValue和firstChild.data也都没问题,只是当你的xml文件中的info段多于一个时,取info[1]的值时,IE下取不到值,firefox下可以取到.到目前为止我还没找到在IE和firefox中都能运行的解析xml的方法.所以只能先针对IE来编程.