JS fetch,没有得到响应的标题 [英] JS fetch, not getting headers on response

查看:16
本文介绍了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,没有得到响应的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆