相关疑难解决方法(0)

Google Maps API:请求的资源上没有"Access-Control-Allow-Origin"标头

我已经看到多个人提出这个问题了,没有一个答案对我有用.

我正在尝试使用react/axios对google maps api进行API调用.

这是我的获取请求:

componentDidMount() {
  axios({
   method : 'get',
   url : `http://maps.googleapis.com/maps/api/js?key=${key}/`,
   headers: {
     "Access-Control-Allow-Origin": '*'
     "Access-Control-Allow-Methods": 'GET',
   },
  })
 .then(function (response) {
  console.log(response);
 })
 .catch(function (error) {
  console.log(error);
 });
}
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

XMLHttpRequest cannot load http://maps.googleapis.com/maps/api/js?
key=xxxxxxxxx/. Response to preflight request doesn't pass access control 
check: No 'Access-Control-Allow-Origin' header is present on the 
requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

我读过其他人都指向https://www.html5rocks.com/en/tutorials/cors/的文章con CORS

但我找不到我的问题的答案.

google-maps xmlhttprequest google-maps-api-3 cors axios

7
推荐指数
1
解决办法
9359
查看次数