typescript - Fetch polyfill 在 Internet Explorer 11 中具有不同的响应对象

标签 typescript internet-explorer babeljs fetch-api polyfills

我目前正在努力使用 Internet Explorer 11Fetch API

我有以下提取调用 unsing TypeScript:

await fetch(theForm.action, { method: theForm.method, body: formData, credentials: "include" })
    .then((response: Response) => {
        if (response.status === 500)
            throw Error(response.statusText);

        if (response.redirected && response.url)
            return window.location.href = response.url;

        return response.json();
    })
    .catch((error: Error) => {
        return this.setState({ isSubmitting: false, internalServerError: error });
    });

代码被 ts 编译为 ES2015,然后使用 babel 编译为 ES5。我还添加了 babel-polyfill。示例代码在 IE 以外的其他浏览器上按预期工作。 事实证明,IE 中的 Response 对象完全不同,甚至没有属性 redirected 并且 url 始终为空。

我应该使用任何 polyfill 来使它在 IE 中工作吗?如果不是,什么是好的解决方法?

最佳答案

MDN's browser compatibility table for Response表示 redirected 属性在 IE 上不可用。

MDN's browser compatibility table for <code>Response</code>

您可以尝试使用类似 https://github.com/github/fetch 的 polyfill连同关于 https://github.com/github/fetch#obtaining-the-response-url 的 API 建议.

关于typescript - Fetch polyfill 在 Internet Explorer 11 中具有不同的响应对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47350959/

相关文章:

reactjs - react-native-web:编译失败(react-native-vector-icons)

typescript - protected 属性的通用 getter 和 setter

javascript - 如何使用 webpack 丑化 javascript

angular - 从 Angular 中的 .subscribe 获取订阅数据

CSS3 过滤器不适用于 ie 10 中的元素

css - 仅由 CSS 提供带有圆形背景的 Bootstrap 字形图标

jquery - jQuery 中的 IE 友好方式确定元素是否为空或仅包含空格或其他空元素?

javascript - Heroku 上未知的代币传播运算符,在本地工作

typescript - '+' 操作的操作数必须是两个字符串或两个数字。考虑使用模板文字 @typescript-eslint/restrict-plus-operands

javascript - Node - 使用 mocha 测试时更改输出颜色