gpt4 book ai didi

json - 获取 : status 302 in Edge 17

转载 作者:行者123 更新时间:2023-12-03 23:21:47 24 4
gpt4 key购买 nike

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

  • 内容长度:0
  • 内容类型:文本/纯文本;字符集=utf-8
  • 地点:http://local.mysite.com/xxx

  • 我的本地网站在 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);
    });

    谢谢你的帮助;)

    最佳答案

    Safari 抛出此错误:

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

    我找到了 the answer :

    The default value for credentials is "same-origin".

    The default for credentials wasn't always the same, though. The following versions of browsers implemented an older version of the fetch specification where the default was "omit":

    Firefox 39-60 Chrome 42-67 Safari 10.1-11.1.2 If you target these browsers, it's advisable to always specify credentials: 'same-origin' explicitly with all fetch requests instead of relying on the default:


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

    关于json - 获取 : status 302 in Edge 17,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52040285/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com