Software Archive
Read-only legacy content
17061 Discussions

Am stuck : Reading Files

John_N_1
Beginner
554 Views

Hi guys, I want to make this code behave quasi-sync ie by the time it reaches the 2nd comment line below, it has finished reading the file. Please help...

var content ;

var oFile //this is got from a loop. No problem here

var reader = new FileReader();
            reader .onload =function(e){ 
           content = e.target.result ;}            
            reader .readAsBinaryString(oFile);

               //make sure u have contents here

0 Kudos
2 Replies
Barry_Johnson
New Contributor I
554 Views

Have you solved the general problem that prompted your question?

0 Kudos
Chris_P_Intel
Employee
554 Views

You'll probably want to use a promise. Makes all things asynchronous much easier.

See this:

https://gist.github.com/jollytoad/4201905

0 Kudos
Reply