fetch 跨域请求问题!

var urls = [
    "xxxxxx",
    "xxxxxxxxx"
];

function(urls) {
    return Promise.all(urls.map(url =>
        fetch(url,{
          mode: "no-cors",
          headers:  {
                      "Content-Type": "text/html;charset=UTF-8",
                    }
        }).then((response) => {
            console.log(response);
            if (response.ok) {
                return response.text();
            } else {
                return {status:response.status};
            }
        })
      )).catch((err)=> {
          return {status:-1};
      })
}

clipboard.png

clipboard.png

跨域请求数据已经拿到,但是response的状态是false是为什么?

阅读 8.3k
3 个回答

看下 statusCode 是不是 >=200 && < 300。这是前端请求不要加 Node.js 标签,前端 fetch 跨域配置如下:

fetch('https://example.com:1234/users', {
  credentials: 'include'
})

参考文档:https://www.npmjs.com/package...

headers去掉试一下~

你的mode配置的是no,,就是不跨域,,但是你又说跨域拿到了数据。。。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题