I'm trying to make a request from the backend using Axios, this is the data that is requested
[
{
"_id": "5ed99cd7972ceb1e203ff3d4",
"model": "76 Runer Nylonmedieval Blue-grey Violet ",
"code": "352077-14",
"brand": "PUMA",
"description": "Corres mucho",
"value": 119000,
"size": 11,
"stock": 50,
"date": "2020-06-05T01:14:17.000Z",
"image": "upload\\352077-14.jpg",
"total": 714000
},
{
"_id": "5edc01f0efed972e1c13c76e",
"model": "Force",
"code": "200-1142",
"brand": "Reebok",
"description": "Perfectos para realizar crossfit, con dos agarres laterales perfectos para Rope Climbing",
"value": 310000,
"size": 45,
"stock": 20,
"date": "2020-06-06T20:50:44.000Z",
"image": "upload\\Screenshot_8.png",
"total": 1240000
},
{
"_id": "5edc0163efed972e1c13c76c",
"model": "Elegant",
"code": "2002-1",
"brand": "Velez",
"description": "comodos y perfectos para ocasiones especiales ",
"value": 340000,
"size": 41,
"stock": 13,
"date": "2020-06-06T20:48:26.000Z",
"image": "upload\\Screenshot_1.png",
"total": 680000
}
]
But when I try to console.log it in my page I just get as a response "data [object Object],[object Object],[object Object]" so I can't use any of the json data. This is the axios request in the frontend:
axios.get('http://localhost:5000/users/carProducts/'+ID.userid)
.then(res =>{
console.log('data '+res.data)
})
.catch(error => console.log(error));
You are getting the data perfectly. the thing is you are logging it wrong.
When you concatenate string with object , output looks like this data [object Object],[object Object],[object Object]
Try passing data as param. You will see the data
console.log('data ',res.data)
let data={'name':'trevor'}
console.log("Details"+data)
console.log("Difference")
console.log("Details",data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With