Document.write(fopen(".txt", "r") {basically}

hi, does anybody know how to :
for( i of fopen(“.txt”,“r”) ){
i cant get it to work : | [ i’m trying to write to the document from a .txt file in javascript.] thank you

what environment are you executing this in? node?

not in node. just writing a HTML file with Javascript in it, that’s all :
I want to write an external .txt file into an HTML page using Javascript. i forgot where i saw the instructions : |

You could use an XLHttpRequest, something like this:

var x = new XMLHttpRequest();
x.onreadystatechange = function(){
  if (this.readyState == 4 && this.status == 200) document.getElementById("container").innerText=this.responseText;
}"GET", "filename.txt", true);

Your web page HTML file and your text file need to be uploaded to the same folder on a server for this to work.

Paragraph formatting will be lost (unless you add more code).


Or you have to change the filename to a resolvable and retrievable URL, at least.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.