I want to read a textfile on my local machine and put the contents into a variable. All the examples I've found use an input button (type = "file") that passes an argument that gets scooped up as "evt" by the function. I simply would pass a filename, like "mydata.txt".
I can do it with ajax, but I would like to use it without XAMPP.
function readSingleFile(evt)
{
var f = evt.target.files[0];
if (f)
{
var r = new FileReader();
r.onload = function(e)
{
var contents = e.target.result;
document.getElementById('div1').innerHTML = contents;
}
r.readAsText(f);
}
else
{
alert("Failed to load file");
}
}