获取:Edge 17 中的状态 302
Fetch : status 302 in Edge 17
我正在使用 js fetch API 从 JSON 检索数据。
它工作正常(即使在 IE 11 中),除了在 Edge 17 中我得到 302,响应 header 是:
- Content-length : 0
- Content-type: text/plain;字符集=utf-8
- 地点:http://local.mysite.com/xxx
我的本地网站在 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:
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'
})
我正在使用 js fetch API 从 JSON 检索数据。 它工作正常(即使在 IE 11 中),除了在 Edge 17 中我得到 302,响应 header 是:
- Content-length : 0
- Content-type: text/plain;字符集=utf-8
- 地点:http://local.mysite.com/xxx
我的本地网站在 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:
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'
})