I want to put the text of a .txt in a variable. I found the following code:
var client = new XMLHttpRequest();
client.open('GET', '/foo.txt');
client.onreadystatechange = function() {
alert(client.responseText);
}
client.send();
Now I am modifying it as follows:
var client = new XMLHttpRequest();
var chaintext = client.open('GET', '/foo.txt');
client.onreadystatechange = function() {
alert(client.responseText);
}
client.send();
console.log(chaintext);
I create a .txt with a phrase in the folder C:\Users\USER\Downloads
But nothing...
The console says "undefined."
I suppose there are several things that may be failing: to start the route is wrong or the directory to which the browser is pointing is another.
Does anyone know how I can write a code that opens a .txt of a specific route?