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

后端 未结 4 731
野趣味
野趣味 2020-12-08 04:30

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 .

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 05:12

    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) {
        // e.target.result should contain the text
    };
    fr.readAsText(file);
    

    Further information here,

    https://developer.mozilla.org/en-US/docs/DOM/FileReader

提交回复
热议问题