Javascript-Edge browser- TypeError:预期的功能

时间:2018-04-18 03:08:48

标签: javascript microsoft-edge

此代码将显示错误:TypeError: Function expected

function btnUploadImageEvent() {
    $(document).on("click", "#btn-upload-image", function () {

        // Iterate all td's in second column
        $("#table-image tbody tr:not(:first-child)").each(function (index, value) {
            var blob = value.cells[5].innerText;
            var fileName = (index + 1) + ".jpg";

            srcToFile(blob, fileName, "image/jpeg")
                .then(function (file) {
                    var formData = new FormData();
                    formData.append("file", file);

                    PassingBlobToServer(formData);
                }, function (error) {
                    MsgBox("Error", error, "error", "#upload-image-modal");
                }).then(function () {
                });
        });
    });
}

function srcToFile(src, fileName, mimeType) {
    return (fetch(src)
        .then(function (res) { return res.arrayBuffer(); })
        .then(function (buf) { return new File([buf], fileName, { type: mimeType }); })
    );
}

我已经阅读了这篇文章:https://docs.microsoft.com/en-us/scripting/javascript/misc/function-expected

但是,我仍然不明白MS说的是什么。 这在我的代码中一定是错的。 请帮助我,非常感谢。

1 个答案:

答案 0 :(得分:2)

(在@Tan Duong的帮助下。)

问题是浏览器的兼容性。

Edge或IE不支持

File() constructor

解决方法:我们可以改用Blob构造函数(受支持):

var blob = new Blob([blobContent], {type : 'image/jpeg'});

引用:https://stackoverflow.com/a/43241922/9156186