I recently work with this simple API, google geocode using Laravel and Axios for API request, but I got this error:
Failed to load https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=AIzaSyB7f2W17hqG9yIQWEcuifem35yK5GOIL08: Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers in preflight response.
I got this in my XHR
Request URL:https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=AIzaSyASQCfY2r2PxAwS24xhdC7pBuG23WYX6kU
Request Method:OPTIONS
Status Code:200
Remote Address:74.125.68.95:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
access-control-allow-origin:*
alt-svc:hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
cache-control:public, max-age=86400
content-encoding:gzip
content-length:592
content-type:application/json; charset=UTF-8
date:Mon, 18 Dec 2017 05:42:31 GMT
expires:Tue, 19 Dec 2017 05:42:31 GMT
server:mafe
status:200
vary:Accept-Language
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
Request Headers
:authority:maps.googleapis.com
:method:OPTIONS
:path:/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=AIzaSyASQCfY2r2PxAwS24xhdC7pBuG23WYX6kU
:scheme:https
accept:*/*
accept-encoding:gzip, deflate, br
accept-language:en,id;q=0.9,en-US;q=0.8
access-control-request-headers:x-csrf-token,x-requested-with
access-control-request-method:GET
origin:https://dikbudtomohon.dev
user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
x-chrome-uma-enabled:1
x-client-data:CJG2yQEIpbbJAQjBtskBCPqcygEIqZ3KAQj/nsoBCKijygE=
Query String Parameters
view source
view URL encoded
address:1600 Amphitheatre Parkway, Mountain View, CA
This is my code:
<script>
geocode();
function geocode() {
axios.get('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=AIzaSyB7f2W17hqG9yIQWEcuifem35yK5GOIL08', {})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
</script>
Please help me...