【问题标题】:Fetch polyfill has different Response-object in internet explorer 11获取 polyfill 在 Internet Explorer 11 中具有不同的响应对象
【发布时间】:2018-05-01 05:58:19
【问题描述】:

我目前正在为Internet Explorer 11Fetch API 苦苦挣扎。

我有以下 fetch-call 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-object 完全不同,甚至没有属性redirectedurl 始终为空。

我应该使用什么 polyfill 在 IE 中完成这项工作吗?如果没有,什么是好的解决方法?

【问题讨论】:

    标签: typescript internet-explorer babeljs fetch-api polyfills


    【解决方案1】:

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

    您可以尝试使用像 https://github.com/github/fetch 这样的 polyfill 以及 https://github.com/github/fetch#obtaining-the-response-url 上的 API 建议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      • 2021-04-01
      • 2016-05-22
      • 2017-06-06
      • 1970-01-01
      • 2014-11-19
      相关资源
      最近更新 更多