4

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?

1 Answer 1

7

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.