I'm just trying to do something that simple. All I want to do is load the contents of a text file into a variable. The text file is only one line and is always a string. I know there are other threads asking the same question, but as of now, the closest answer I have gotten is this:
var client = new XMLHttpRequest();
client.open('GET', '/foo.txt');
client.onreadystatechange = function() {
alert(client.responseText);
}
client.send();
The problem with this is that I am trying to load the information into a variable. Not send it as an alert. I have tried this:
var string;
var client = new XMLHttpRequest();
client.open('GET', '/foo.txt');
client.onreadystatechange = function() {
string = client.responseText;
}
client.send();
This does not work either.
This is not a duplicate of this post, as that post is focused on Ajax, and doesn't actually answer how to import the information. I'm not utilizing Ajax. I want the information from the file to be usable elsewhere in the program.