Estoy tratando de cargar un archivo de texto para analizarlo e insertarlo en el documento de ms, pero los métodos estándar de JavaScript no parecen funcionar.
He intentado
var client = new XMLHttpRequest(); client.open('GET', '/foo.txt'); client.onreadystatechange = function() { alert(client.responseText); } client.send();e intenté acceder por
document.getElementById("file-id").files[0]pero HTMLElement no tiene la propiedad 'archivos' en la API de Word
Recomendé usar fetch() para cargar todos los archivos como .txt en JavaScript.
Para texto:
fetch('foo.txt').then(x => x.text()).then(y => alert(y));Para JSON:
fetch('foo.txt').then(x => x.json()).then(y => alert(y));Para imágenes:
fetch('me.jpg').then(x => x.blob()).then(y => document.getElementById('demo').src = URL.createObjectURL(y));