Reputation: 33
Hello there hope you are doing well!
I'm tring to fetch some data from the db but for some reason the request goes through in postman but when I try it with axios is gives me:
400 bad request Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)
Here is my code:
useEffect(() => {
const fetchItems = async () => {
try {
const response = await axios.get('http://127.0.0.1:5000/orderhis',
{data: {"user_id":87}}
);
setData(response.data)
} catch(err) {
if (err.response) {
console.log(err.response.data);
console.log(err.response.status);
console.log(err.response.headers);
}
else{
console.log(`Error: ${err.message}`);
}
}
}
fetchItems();
}, []);
In Postman:
But in the Browser:
PS Here is the route code in case it helps:
def order_history():
if request.method == 'GET':
user_id = request.json['user_id']
is_user = BaseUser().getUserID(request.json)
if is_user[1] == 404:
return is_user
return OrderController().get_order_history(user_id)
return jsonify(Error='Method not allowed'), 405
Thanks and have a great day!
Upvotes: 0
Views: 801
Reputation: 345
You're setting params like this: {data: {"user_id":87}}
, but in axios you need to set params with: {params: {"user_id":87}}
Upvotes: 0