问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/13729301/html5-file-api-how-to-see-the-result-of-readastext