json - 获取:Edge 17 中的状态 302
问题描述
我正在使用 js fetch API 从 JSON 中检索数据。它工作正常(即使在 IE 11 中),除了在 Edge 17 中我得到 302,响应头是:
- 内容长度: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
我找到了答案:
凭据的默认值是“同源”。
但是,凭据的默认值并不总是相同的。以下版本的浏览器实现了旧版本的 fetch 规范,默认为“省略”:
Firefox 39-60 Chrome 42-67 Safari 10.1-11.1.2 如果您针对这些浏览器,建议始终在所有获取请求中明确指定凭据:'same-origin',而不是依赖默认值:
fetch('/users', {
credentials: 'same-origin'
})
推荐阅读
- c - 无法访问 BeagleBone Black GPIO
- jquery - Jquery Modal Popup打开后调用函数
- javascript - 使用 Knex 查询动态更改数据库
- ios - 具有不同宽度单元格的水平集合视图
- flutter - 在构建 Builder(dirty) 时抛出了以下 FormatException: FormatException in flutter
- vue.js - axios.get 调用后如何获取数据的属性值?
- mysql - 添加外键约束失败。缺少约束索引
- javascript - createReadStream is not present in uploaded image
- omnet++ - 我可以将 omnet++ 用于视频跟踪文件吗?
- amazon-web-services - AWS Glue 对 S3 上不断到达的数据进行增量爬取