简体   繁体   中英

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

I believe what you want is:

axios.put(`http://localhost:5000/api/tasks/${id}`, {
            description: descript
        })
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));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM