0

I'm trying to get a list from a website and then add it to my popup.html file. The only time i've been able to edit the popup.html file from the content.js is when i remove the parsing section. How would i add the parsed xml response to my popup.html, or is there another way to get an element without parsing the response?

var list;
 function getAlerts() {
    var xhr = ("XMLHttpRequest" in window) ? new XMLHttpRequest() : new        ActiveXObject("Msxml3.XMLHTTP");
    xhr.open("GET", 'http://www.example.com/', true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status==200) {
            var data = xhr.responseText;
            var parser = new DOMParser();
            var xmlDoc = parser.parseFromString(data, "text/html");
            list = xmlDoc.getElementById("grabsomeelements");
            console.log(list);
        }
    };
    xhr.send(null);

}

document.addEventListener('DOMContentLoaded', function () {
    getAlerts();
    document.getElementById("somethinghere").innerHTML=list;
});
Roblox
  • 47
  • 5
  • Simply move the `document.getElementById("somethinghere").innerHTML=list;` line inside the callback after `console.log` and make sure to read about the asynchronous code. – wOxxOm Oct 04 '15 at 09:16
  • I solved it by making a temp element and then setting it's innerHTML to the variable instead of parsing the XML. – Roblox Oct 04 '15 at 09:31

0 Answers0