HTML5 File API: How to see the result of readAsText()

When readAsText() function is completed the result is stored in .result

How do I see if the content of the file read are correct in .result?

 fr = new FileReader();
 var x = fr.result;
 console.log(x); //does not display anything on console

Now how do I display the .result object to verify the the content?


readAsText is asynchronous, so you would need to use the onload callback to see the result.

Try something like this,

var fr = new FileReader();
fr.onload = function(e) {
    // should contain the text

Further information here,

Leave a Reply

Your email address will not be published. Required fields are marked *