JS fetch, not getting headers on response(JS fetch,没有得到响应的标题)
问题描述
我正在使用 fetch 向 wordpress api 发出请求,但我在响应中得到一个空的 headers 对象,有人知道为什么吗?
I'm making a request using fetch to wordpress api, but I get a empty headers object on the response, anyone knows why?
这是我的获取操作
export const getJobs = () => {
return dispatch => {
fetch(endpoints.jobs)
.then(res => res.json())
.then(data => dispatch(setJobs(data)))
}
};
这是我在做 res.json 之前得到的对象
and here's the object that I get before doing res.json
body: (...)
bodyUsed: false
headers: {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "cors"
url: "url"
关于如何从响应中获取所有标头的任何想法?
any ideas on how I can get all the headers from the response?
推荐答案
使用 CORS 时访问响应头有限制.由于您的响应类型是 cors,这可能是罪魁祸首.
There is a restriction on accessing response headers when using CORS. Since your response type is cors that might be the culprit.
请参阅此 详细回答.
这篇关于JS fetch,没有得到响应的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JS fetch,没有得到响应的标题
基础教程推荐
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
