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

160
Vistas
Axios Post is not completing every time

Iam new to React and I got some problems.

This is my current API call.

Axios.post(Addr_currentRound_addOne, { gameId: gameId }).then(history.push("/leiter_tunierplan/"+gameId));

And this is the corresponding API Code snippet.

app.post("/currentRoundAddOne", (req, res) => {

  
  const gameId = req.body.gameId;
    
  db.query(
    "UPDATE tunierplan SET currentRound=currentRound+1 WHERE id=?;",
    [gameId],
    (err, result) => {
      if (err) {
        console.log(err);
      } else {
        res.send("Daten Übertragen");
      }
    }
  );
});

The problem here: currentRound, should allways when the call is executed increased by +1. And then Redirect to the given "/leiter_tunierplan/" BUT From time to time, it does not work. Its not increasing it by any Value (+1) My first thought is: Because its async it my be canceled from the history.push, befor it got completed. Am i right? And how can i fix it. Thanks allready.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Is game gameId the already incremented id for the next page? I don't see it being incremented anywhere in your code.

If so, try putting history.push in a callback, like this:

...then(() => history.push("/leiter_tunierplan/"+gameId));

This is because then takes a callback function as a parameter

about 4 years ago · Juan Pablo Isaza Denunciar

0

The Solution to all is to add preventDefault(); My Problem was, that the side got reloaded..

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think you try async-await as the request to the database is promise-based. My suggestion:

app.post("/currentRoundAddOne", async (req, res) => {
    const gameId = req.body.gameId
    const data = await db.query("UPDATE tunierplan SET currentRound=currentRound+1 WHERE id=?;", [gameId],
    (err, result) => {
          if (err) console.log(err);
    }
    console.log(data) // check updated data, it should return id
})

I hope it works!

about 4 years ago · Juan Pablo Isaza Denunciar
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