FileReader.readAsDataURL()仅在使用chrome进行调试时出错

时间:2015-04-18 10:39:55

标签: javascript jquery google-chrome filereader

我的代码在chrome和IE中都按预期工作。它使用输入类型文件更新模式占位符div,其中包含使用输入类型文件选择的新图像的来源。仅在chrome中调试时(IE中的调试工作正常)并且在readAsDataURL方法上放置了断点,它会出错并中断。任何人都可以解释为什么它会产生这个错误吗?

错误:

Uncaught InvalidStateError: Failed to execute 'readAsDataURL' on 'FileReader':
The object is already busy reading Blobs.(anonymous function)
@ pageName.aspx?id=1234:192m.event.dispatch
@ jquery.min.js:3r.handle @ jquery.min.js:3

我的代码:

$("#imageInput").change(function () {
    if (this.files && this.files[0]) {
        var reader = new FileReader();
        reader.onloadend = function (e) {
            $("#modalImagePlaceHolder").attr("src", e.target.result);
        };
        reader.readAsDataURL(this.files[0]);
    } else {
        $("#modalImagePlaceHolder").attr("src", $("#defaultImage").attr("src")).width(480).height(385);

    }
});

0 个答案:

没有答案