2 回答

TA貢獻1809條經(jīng)驗 獲得超8個贊
jsfiddle 鏈接中提到的解決方案。替換 responseText 上的字符而不是 responseXml。您可以在成功替換所需字符后將該 xmltext 轉換為 xmldocument。
http://jsfiddle.net/ogaq9ujw/2/ var response=request.responseText;
var xmlText=response.replace('GM',"and");

TA貢獻1821條經(jīng)驗 獲得超5個贊
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();
添加回答
舉報