首页 > 解决方案 > IE 11 react 'promise' 未定义

问题描述

我正在尝试加载使用 react 构建的页面。当页面加载时,有一个使用反应呈现的表格。此表当前未在 IE 上加载,并抛出错误 promise is not defined。与承诺完全相同的代码适用于其他浏览器。下面是代码。

fetchData(url) {
    // Return a new promise.
    return new Promise(function (resolve, reject) {
        $.ajax(
            {
                url: url,
                cache: false,
                context: this,
                dataType: 'json',   // we're expecting JSON as a response
                data: {},
                method: "GET",
                contentType: "application/json; charset=utf-8",
                success: function (data, status, xhr) {
                    resolve(JSON.parse(data));
                },
                error: function (xhr, status, httpErrorText) {
                    reject(httpErrorText);
                }
            });
    });
}

任何想法为什么会发生这种情况以及如何解决这个问题。

标签: javascriptreactjsfrontend

解决方案


我遇到过同样的问题。我添加了以下行,public/index.html其中修复了所有 IE11 polyfill 并且它起作用了:

<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=es6"></script>

推荐阅读