Jul*_*ZAL 2 json http-status-code-302 microsoft-edge fetch-api
我正在使用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
Run Code Online (Sandbox Code Playgroud)
这是我的访存电话:
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);
});
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助;)
Safari抛出此错误:
unhandled promise rejection syntaxerror the string did not match the expected pattern
Run Code Online (Sandbox Code Playgroud)
我找到了答案:
凭据的默认值为“ same-origin”。
但是,凭据的默认值并不总是相同。以下版本的浏览器实现了获取规范的旧版本,其中默认值为“忽略”:
Firefox 39-60 Chrome 42-67 Safari 10.1-11.1.2如果定位到这些浏览器,建议始终指定凭据:对所有获取请求都明确指定“ same-origin”,而不要依赖默认设置:
fetch('/users', {
credentials: 'same-origin'
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
785 次 |
| 最近记录: |