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

240
Visualizações
run javascript code after python if statement

I am trying to achieve the following. In my python code I have a if statement that checks for the response from a API server. if the response is 201 I want to run a code snippet inn javascript. The response is determined after a form is submitted in html.

I have then declared a variable globally and that variable is set to false. After the response is 201 i set this variable to true. If this variable is true i want to run a code snippet.

        submit = False
        if response == 201:
            submit = True
            response_page = redirect("next_url")
            # redirect to next step
            return response_page

Inn my javascript code I check for the variable like so:

    function setData(){
        if('{{submit}}'=="True"){
            #Run code
        }
    }

The setData() function is run when the form is submitted. But it doesn’t work because the function does not wait for the server response. Any one have any ideas on how I can achieve this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I assume that u don't want to fetch it through js. maybe do setInterval() and clearInterval()

let setData;
if (!setData) {
setData = setInterval(function setData(){
    if('{{submit}}'=="True"){
        #Run code
        clearInterval(setData);
    }
  }, 1000);
}

I'm pretty new hope it helps.

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