当 readAsText()
函数完成时,结果存储在 .result
中
如何在.result
中查看读取的文件内容是否正确?
fr = new FileReader();
fr.readAsText(file);
var x = fr.result;
console.log(x); //does not display anything on console
现在如何显示 .result
对象来验证内容?
最佳答案
readAsText
是异步的,因此您需要使用 onload
回调来查看结果。
尝试这样的事情,
var fr = new FileReader();
fr.onload = function(e) {
// e.target.result should contain the text
};
fr.readAsText(file);
这里有更多信息,
关于javascript - HTML5 文件 API : How to see the result of readAsText(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13729301/