Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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));
    }
like image 712
Matthew Spahr Avatar asked Oct 21 '25 21:10

Matthew Spahr


2 Answers

I believe what you want is:

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

because the second parameter would be the data, and third as config: axios.put(uri, data[, config]).

like image 85
G Gallegos Avatar answered Oct 23 '25 10:10

G Gallegos


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));
}
like image 29
Manish Sharma Avatar answered Oct 23 '25 10:10

Manish Sharma