gpt4 book ai didi

javascript - HTML5 文件 API : How to see the result of readAsText()

转载 作者:技术小花猫 更新时间:2023-10-29 11:45:20 27 4
gpt4 key购买 nike

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);

这里有更多信息,

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

关于javascript - HTML5 文件 API : How to see the result of readAsText(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13729301/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com