I'm trying to load text file to parse it and insert into ms-document, but standard JavaScript methods doesn't seem to work.
I've tried
var client = new XMLHttpRequest();
client.open('GET', '/foo.txt');
client.onreadystatechange = function() {
alert(client.responseText);
}
client.send();
and tried accessing by
document.getElementById("file-id").files[0]
but HTMLElement doesn't have 'files' property in Word API
I recommended using fetch() to load all files like .txt in JavaScript.
For text:
fetch('foo.txt').then(x => x.text()).then(y => alert(y));
For JSON:
fetch('foo.txt').then(x => x.json()).then(y => alert(y));
For images:
fetch('me.jpg').then(x => x.blob()).then(y => document.getElementById('demo').src = URL.createObjectURL(y));