1

I'm probably doing something wrong, but I can not find the reason.

I try to perform a GET using axios, which if I do it from postman the answer is correct, but from axios it returns the data to null.

Postman:

{
    "direccion": "Castelldefels, Spain",
    "lat": "41.279999",
    "lng": "1.970000"
}

Code JS:

var boton = document.getElementById('location');
boton.addEventListener('click', function() {
    loading.style.display = 'block';
    axios.get('https://restserver-test-jsg.herokuapp.com/location?location=Castelldefels', {
            responseType: 'json',
        })
        .then(function(res) {
            if (res.status == 200) {

                console.log(res);

                mensaje.innerHTML = res.data;
            }
            console.log(res);
        })
        .catch(function(err) {
            console.log(err);
        })
        .then(function() {
            loading.style.display = 'none';
        });
});

The answer I see from the Chrome console is: chrome

If I perform this operation from the browser, it returns what was expected. https://restserver-test-jsg.herokuapp.com/location?location=Castelldefels

Thank you!

Nimrock
  • 23
  • 1
  • 5

1 Answers1

1

Is it just a syntax error with axios? There probably shouldn't be a comma after the responseType key in the configuration object.

Edit:

Ah, I see. It looks to be a CORS error with heroku. Check this question for the answer: Allow CORS REST request to a Express/Node.js application on Heroku

R. Bailey
  • 26
  • 2