我正在尝试从其他页面获取#test1
并将其附加到主页的#test3
。这是我到目前为止所做的:
<div id="test3"></div>
var request = new XMLHttpRequest();
request.open('GET', '//jsbin.com/wemowe', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var resp = request.responseText;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(resp,"text/xml");
var tds = xmlDoc.getElementById("test1");
console.log(xmlDoc);
document.getElementById('test3').innerHTML=tds.innerHTML;
} else {}
};
request.onerror = function() {};
request.send();
是否有任何建议让它发挥作用?
答案 0 :(得分:6)
doc类型导致此问题。
var xmlDoc=parser.parseFromString(resp, "text/xml");
将其更改为:
var xmlDoc=parser.parseFromString(resp, "text/html");