Matthew Spahr
Matthew Spahr

Reputation: 105

Axios put request, sending params and data

I have a simple todo app and am working on the edit task feature. My backend appears to be working correctly when tested. I am looking for req.body.description. I am editing the task by id. When I save the edit, nothing happens inside my database. My function is as follows, why does this not work?

function editTask(task) {
        const id = task.parent().parent().attr('id');
        const descript = task.parent().prev().text();
        axios.put('http://localhost:5000/api/tasks/:id', {
            params: {
                id: id
            },
            description: descript
        }).then(res => {
            console.log(res);
        }).catch(err => console.error(err));
    }

Upvotes: 3

Views: 1188

Answers (2)

Manish Sharma
Manish Sharma

Reputation: 249

function editTask(task) {
   const id = task.parent().parent().attr('id');
   const descript = task.parent().prev().text();

   axios.put("http://localhost:5000/api/tasks/"+id, {
           description: descript
        }).then(res => {
            console.log(res);
        }).catch(err => console.error(err));
}

Upvotes: 0

G Gallegos
G Gallegos

Reputation: 609

I believe what you want is:

axios.put(`http://localhost:5000/api/tasks/${id}`, {
            description: descript
        })

Upvotes: 2

Related Questions