Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Fetching Data with Axios

Axios CORS Problem

I'm trying to fetch some data from Google API, but the response : No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. how can I fixed this?

axios.get(`https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=${apiKey}`)
         .then(response => {
            console.log(response);
         })
         .catch(error => {
            console.log('Error fetching and parsing data', error);
         });

2 Answers

Adam Beer
Adam Beer
11,314 Points

Hi Kenji. I am not sure, but please use backticks. For Example:

axios.get(`https://maps.googleapis.com/maps/api/place/details/jsonplaceid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=${apiKey}`)
.then()
.catch();

hi adam, actually I put backticks in there, but I didn't notice it was gone when I paste it here. anyway, even I put backticks the response is still the same. any solution? thanks by the way!

Adam Beer
Adam Beer
11,314 Points

I misspelled before but now I fixed, please check.

Adam Beer
Adam Beer
11,314 Points

You show the whole code?