Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

645
Visualizações
Error while deleting, saying: 'Request failed with status code 404', name: 'AxiosError', code: 'ERR_BAD_REQUEST'

I am currently creating a Supplements store system and I am using MERN Stack and Axios. I cannot figure out why the delete function isn't working. I am new at this so please have a look at this.

P.S. : The backend of the code is working fine. I checked it with the POSTMAN. The issue is with the onDelete function.

Backend

    router.route("/delete/:id").delete(async (req,res) => {
    let supplementId = req.params.id;

    await Supplement.findByIdAndDelete(supplementId)
    .then(() => {
        res.status(200).send({status: "Supplement Deleted"})
    }).catch((err)=>{
        console.log(err);
        res.status(500).send({status: "Error when deleting data", error : err.message});
    });
})

Front end

Delete Operation

    const getData = () => {
    axios.get(`http://localhost:8000/supplement/`)
    .then((res) => {
      setSupplements(res.data);
    })
  }

  const onDelete = (id) => {
    axios.delete(`/delete/${id}`)
    .then(() => {
      alert("Deleted Successfully!")
      getData();
    })
    .catch((err) => 
        {
          alert(err.message);
        });
  }

Button

<Button variant="outline-danger" onClick={() => 
              onDelete(supplement._id)}>
                Delete</Button>
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda