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!