Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

644
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda