I know this question has asked before, but I’m still learning JavaScript, and I’m having trouble seeing through the complexity of other people’s answers. I have a text file in the same directory as an HTML file that’s reading JavaScript, and that text file literally has one line in it. I want to be able to grab that line out of the text file and put it in a string. What’s a really simple way to do this that’ll work in FF, IE, and Chrome, and is, aside from browser choice, is fairly universally valid? Again, I know this has been asked before, but I’m having trouble picking the real method here out of the complexity of example code I’ve seen elsewhere. Thanks!
I know this question has asked before, but I’m still learning JavaScript, and I’m
Share
Use jQuery get method http://api.jquery.com/jQuery.get/
The url variable can be relative, so you could put the text filename there. For example if your text file is called “mytext.txt” and in the same directory of the script accessing it you put:
Note this answer assumes you are using http to access the text file and both script and text file is in the same domain.