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

162
Visualizações
API Request from React frontend to Flask backend returns null on the first request only

I have a React frontend that communicates with a Flask backend, and for the most part it works fine. However, every time I make the first API request, the backend will send an error. After that, everything works fine. I suspect that there is some issue with my JavaScript not waiting for the API response properly, but I do not know exactly what is going on.

The code for my API request is listed below:

const handleSubmit= (e) => {
    e.preventDefault();
    const data = {"locationType": locationType, 
                  "numLocations": numLocations, 
                  "city": city};
    alert("Successfully submitted!");
    axios
      .post(url, data)
      .then(res => {
        setResult(JSON.stringify(res.data.resultsList));
        //console.log(result);
        addShops(result);
      })
      .catch(err => console.log(err));
      return JSON.stringify(result);
  }

In addition, the code for my POST response is listed here:

  def post(self):
    print(self)
    parser = reqparse.RequestParser()
    parser.add_argument('locationType', type=str)
    parser.add_argument('numLocations', type=int)
    parser.add_argument('city', type=str)

    args = parser.parse_args()
    location = args['locationType']
    num_locations = args['numLocations']
    city = args['city']

    if location:
      message = calculate(location, num_locations, city)
    else:
      message = "No Msg"
    
    return message

Please let me know if more information is needed to answer the question! Thank you!

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