I have an object in HTML like this:
<object id="data" type="text/plain" data="test.txt"></object>
test.txt
var data = document.getElementByID("data");
The object
tag has to make a separate request to the server and then load that content. Meanwhile, your JavaScript has already executed and "misses the bus."
Run your code inside the onload
event of the object
.
Then use .contentDocument.body.childNodes[0].innerHTML
to see the text file.
var object = document.getElementByID("data");
object.onload = function() {
var data = object.contentDocument.body.childNodes[0].innerHTML);
// use the data
};