I'm trying to get #test1
from another page and append it to #test3
of the main page. This is what I have done so far:
<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();
Here is JSBin
Any suggestion to make it work?
The doc type is causing the issue here.
var xmlDoc=parser.parseFromString(resp, "text/xml");
change it to:
var xmlDoc=parser.parseFromString(resp, "text/html");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With