Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ';无访问控制允许原始标头';从Deezer Api获取数据时出错_Javascript_Reactjs_Api_Fetch_Restful Authentication - Fatal编程技术网

Javascript ';无访问控制允许原始标头';从Deezer Api获取数据时出错

Javascript ';无访问控制允许原始标头';从Deezer Api获取数据时出错,javascript,reactjs,api,fetch,restful-authentication,Javascript,Reactjs,Api,Fetch,Restful Authentication,我正在创建一个React应用程序,从 目前,我正在尝试获得顶级专辑: 我创建了一个请求数据的函数 fetchTopAlbums = () => { return fetch('https://api.deezer.com/chart/0/tracks', { 'Accept': 'application/json', }) .then((res) => res.json()) } 调用此函数时,我在控制台中遇到此错误 Access to fetch at '

我正在创建一个React应用程序,从

目前,我正在尝试获得顶级专辑:

我创建了一个请求数据的函数

fetchTopAlbums = () => {
    return fetch('https://api.deezer.com/chart/0/tracks', { 'Accept': 'application/json', })
      .then((res) => res.json())
  }
调用此函数时,我在控制台中遇到此错误

Access to fetch at 'https://api.deezer.com/chart/0/tracks' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

deezer api正在限制从网站进行的api调用。它这样做是为了专门阻止你正在尝试做的事情。通常,这是阻止意外网站访问其他网站后端的目的。有些服务允许任何站点访问这些服务,有些则要求您通过您所在的站点和相关API之间的后端访问该服务。

您为什么不研究cors是什么。您需要将cors添加到您的服务器中好的,我相信我现在对这一点理解得更好了。非常感谢。