Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
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 answers
Answer question

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 Report

0

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

about 4 years ago · Juan Pablo Isaza Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!