Search code examples
javascriptaxiosput

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));
    }

Solution

  • 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));
    }