Estoy tratando de averiguar cómo reemplazar el texto HTML usando el código js, el objetivo es leer un archivo "1.txt" con un nombre y reemplazar el texto HTML (¡Reemplázame!) si alguien puede ayudarme y señalarme en la dirección correcta.
esto es lo que tengo ahora
<body class="htmlNoPages"> <div id="main"><p>Replace me!!</p></div> </body> <script type="text/javascript" id="gwd-init-code"> function load() { // var text = ('test 123') var file = new XMLHttpRequest(); file.open(GET,'file:///d:/1.txt', true); file.responseType =Text; file.onreadystatechange = function() { if (file.readyState === 4) { // Makes sure the document is ready to parse if (file.status === 200) { // Makes sure it's found the file text = file.responseText; } } } let element = document.querySelector('#main'); element.innerHTML = text; } window.onLoad = load(); </script>lo hice así
var TxtFile = new XMLHttpRequest(); TxtFile.onreadystatechange = function () { var allText = "Uw browser is niet compatibel of u heeft uw java script disabeld staan"; if (TxtFile.readyState === XMLHttpRequest.DONE && TxtFile.status == 200) { allText = TxtFile.responseText; allText = allText.split("\n").join("<br>"); } document.getElementById('planning').innerHTML = allText; } TxtFile.open("GET", 'File location', true); TxtFile.send(null);