Home > database >  Axios delete from mysql db gives error 404
Axios delete from mysql db gives error 404

Time:06-15

I get error when I try to delete a record from the database:

Uncaught (in promise) AxiosError {message: 'Request failed with status code 404', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}

Code

 Axios.delete('http://localhost:3001/api/delete/rec', { data: props.recipe[0].ID }).then((res) => {
        console.log(res);
    })

DB

app.get('/api/delete/rec', (req, res) => {
const dataID = req.body.data;

const sqlSelect = "DELETE FROM `recipes` WHERE ID = ?";

db.query(sqlSelect, dataID, (err, result) => {
    console.log(result);
    console.log(err);
});

})

When I temporarily change the questionmark to the ID in the dB it actually deletes it. So I assume it's an issue with Axios?

CodePudding user response:

Try this:

current code: app.get('/api/delete/rec', (req, res) => {

proposed solution: app.delete('/api/delete/rec', (req, res) => {

  • Related