Erik ELN
Erik ELN

Reputation: 72

Failed to retrieve data with axios get from a date (Reactjs)

I need to retrieve data based on a date. I tested my route with Postman and everything works fine. However, when I do my axios query with a date, it returns an empty array. I understood that it would be a date format problem with axios, but I couldn't solve it. Could you help me please?

Here is my code in the front:

const getDailyWorking =()=>{
    let datas={
        activity_creationTimestamp: ('2022-06-28'),
        user_id:1
    }

    console.log(datas)
    return axios.get(config.api_url+'/dailyWork', datas).then((response)=>{
        console.log(response.data)
    }).catch((err)=>{
        console.log(err)
    })
}

Upvotes: 0

Views: 424

Answers (2)

vvxhid
vvxhid

Reputation: 111

You can specify the GET parameters like this axios.get('/path', { params: datas } which is equivalent to axios.get('/path?activity_creationTimestamp=2022-06-28&user_id=1') . Otherwise, provide more information about the server side route.

Upvotes: 0

Jose Loui
Jose Loui

Reputation: 36

You're using the wrong type of request. A GET request can't include a body in the request, while a POST request can include a body in the request. Maybe you should check the documentation again and get the parameters sorted.

Upvotes: 2

Related Questions