I am using the File API to read a file in javascript. Is there a way to do this without creating an event with “reader.onload = function(e)”?
I want it work in the code below. As it is now the variable fileContent doesn’t contain anything when I try to read it.
I understand why the code below doesn’t work like that but is there any other way to make it work like that?
Do someone understand what I am trying to achieve?
[CODE]var fileContent;
function myFunction()
{
readFile();
processData();
}
function readFile()
{
file = myFiles[0];
var reader = new FileReader();
reader.onload = function(e)
{
fileContent = e.target.result;
}
reader.readAsText(file);
}
function processData()
{
alert(fileContent);
}