Reputation: 37
I'm trying to parse a XML document from an API link....
However when I try to use the code div.innerHTML=request.responseText it won't parse the text into the div unlike it does in the alert which is called in the line before.
<div id="myDiv"></div>
<script>
var url = 'http://www.bea.gov/api/data/?&userID=XXXXX&method=GETDATASETLIST&ResultFormat=XML&';
div = document.getElementById("myDiv");
request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function() {
data = request.responseText;
alert(data);
div.innerHTML = data;
};
request.send();
</script>
Any reason why the alert function is working but the div.innerHTML function is not working for the request.responseText?
Upvotes: 0
Views: 1868
Reputation: 1492
var url = 'http://www.bea.gov/api/data/?&userID=XXXXX&method=GETDATASETLIST&ResultFormat=XML&';
var div = document.getElementById("myDiv");
request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function() {
data = request.responseText;
console.log(data);
div.textContent = data;
};
request.send();
This should work.
Upvotes: 1