I am trying to read a file that is selected using an input type file in an html page. I implemented a function to read the file, and the contents of the file can be read. But the actual problem is that reading the contents of the file is asynchronous , which allows other script functions to be performed. I save the contents of a file read in an array.
When moving to other functions, the array is empty. When a delay is introduced, the array has content. Can someone help me solve this problem without introducing a delay?
My code to read the file
var getBinaryDataReader = new FileReader(); getBinaryDataReader.onload = (function(theFile) { return function(frEvnt) { file[fileCnt]=frEvnt.target.result; } })(document.forms[formPos].elements[j].files[0]); getBinaryDataReader.readAsBinaryString(document.forms[formPos].elements[j].files[0]);
Thanks in advance.
source share