我正在使用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('/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:
凭证的默认值是“同源”。
但是,凭据的默认值并不总是相同。以下版本的浏览器实现了旧版本的获取规范,其中默认为“省略”:
Firefox 39-60 Chrome 42-67 Safari 10.1-11.1.2如果您定位这些浏览器,建议始终使用所有提取请求显式指定凭据:“same-origin”,而不是依赖于默认值:
fetch('/users', {
credentials: 'same-origin'
})