2 回答
![?](http://img1.sycdn.imooc.com/533e4d00000171e602000200-100-100.jpg)
TA贡献1809条经验 获得超8个赞
jsfiddle 链接中提到的解决方案。替换 responseText 上的字符而不是 responseXml。您可以在成功替换所需字符后将该 xmltext 转换为 xmldocument。
http://jsfiddle.net/ogaq9ujw/2/ var response=request.responseText;
var xmlText=response.replace('GM',"and");
![?](http://img1.sycdn.imooc.com/54586425000103f602200220-100-100.jpg)
TA贡献1821条经验 获得超4个赞
1) 你的请求是同步的,因为你使用了 send(...,FALSE)。在您的情况下,异步不是问题。
2) 使用console.log (xml) 签入控制台。不要在 html页面中显示它并注释替换行,因为此 var 的内容显示可以实时更改,随时可以更改。看看它是否真的是一个pur & in属性。
var xml = request.responseXML;
/* var xml = xml.replace (/&/g, "and"); */
console.log (xml);
3) 但是:& 在属性 xml 中无效,必须替换为 & 在 xml 的制作过程中。谁生成这个 xml 文件?您或第三方服务,或其他程序员?
4) 替换 & 不是解决方案:想象一下,稍后在 xml 中,您找到了一个有效的字符串
<text> here & there </text>
它会变成
<text> here and;amp; there </text>
5) 尝试使用 responseText 而不是 xmlResponse :这是浏览器尝试解析它之前的完整原始响应。
var xhr = new XMLHttpRequest();
xhr.open('GET', '/ODDS/odds3.xml');
xhr.onload = function() {
if (xhr.status === 200) {
alert('response is' + xhr.responseText);
}
else {
alert('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
添加回答
举报