HTML5文件API:FileReader.readAsText()返回"undefined"

Cla*_*tin 17 javascript html5 filereader fileapi

我在Mac OS X上使用Chrome 12,我在文档中包含了jQuery 1.6.1.

我尝试将文件的内容作为文本读取,并使用以下函数将其保存在数据对象中:

this.upload = function(file) {
    console.log('FileHandler.upload called with ' + file.name + '.');
    console.log(file);
    console.log(this.reader);

    data = {
        content: this.reader.readAsText(file)
    }

    console.log('Content: ' + data.content);
}
Run Code Online (Sandbox Code Playgroud)

"file"接缝是有效的文件对象,"this.reader"是FileReader类型的新实例.此代码创建以下控制台输出:

http://cl.ly/1Y2b383G2F272x1m1P0N

在此输入图像描述

pim*_*vdb 13

根据文档,这不是它的工作方式.你应该调用这个readAsText()函数,当它完成时,结果存储在.result.