HTML5文件API:如何查看readAsText()的结果 [英] HTML5 File API: How to see the result of readAsText()
本文介绍了HTML5文件API:如何查看readAsText()的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当 readAsText()
功能完成时,结果存储在 .result
如何在 .result
中查看所读取文件的内容是否正确?
fr = new FileReader();
fr.readAsText(file);
var x = fr.result;
console.log(x); //在控制台上不显示任何内容
现在我该如何显示。结果
对象验证内容?
解决方案
onload
回调来查看结果。
尝试像这样的东西,
var fr = new FileReader();
fr.onload = function(e){
// e.target.result应该包含文本
};
fr.readAsText(file);
更多信息请点击这里
https://developer.mozilla.org/zh-CN/docs/DOM/FileReader a>
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();
fr.readAsText(file);
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) {
// e.target.result should contain the text
};
fr.readAsText(file);
Further information here,
https://developer.mozilla.org/en-US/docs/DOM/FileReader
这篇关于HTML5文件API:如何查看readAsText()的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文