【问题标题】:Fetch : status 302 in Edge 17获取:Edge 17 中的状态 302
【发布时间】:2019-02-02 01:11:01
【问题描述】:

我正在使用 js fetch API 从 JSON 中检索数据。 它工作正常(即使在 IE 11 中),除了在 Edge 17 中我得到 302,响应头是:

我的本​​地网站在 Mac 上,我正在使用 BrowserSync 使其可通过 192.168.100.X:3000 访问 然后我像这样更新了我的 PC 主机文件:

192.168.100.X  http://local.mysite.com

这是我的 fetch 调用:

   fetch('/fr/fil-actualites-json', { mode: 'cors' })
      .then(
        function(response) {
          console.log('code :' +response.status);
          if (response.status !== 200) {
            console.log('Looks like there was a problem. Status Code: ' +
              response.status);
            return;
          }

          // Examine the text in the response
          response.json().then(function(data) {
            // do some stuff
          });
        }
      )
      .catch(function(err) {
        console.log('Fetch Error :-S', err);
      });

感谢您的帮助;)

【问题讨论】:

    标签: json microsoft-edge fetch-api http-status-code-302


    【解决方案1】:

    Safari 抛出了这个错误:

    unhandled promise rejection syntaxerror the string did not match the expected pattern
    

    我找到the answer

    凭据的默认值为“same-origin”。

    不过,默认的凭据并不总是相同的。这 以下版本的浏览器实现了旧版本的 获取默认为“省略”的规范:

    Firefox 39-60 Chrome 42-67 Safari 10.1-11.1.2 如果您针对这些 浏览器,建议始终指定凭据:'same-origin' 显式处理所有 fetch 请求,而不是依赖默认值:

    fetch('/users', {
      credentials: 'same-origin'
    })
    

    【讨论】:

      猜你喜欢
      • 2015-12-29
      • 2011-09-12
      • 2017-10-16
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多