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

239
Vistas
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 Respuestas
Responde la pregunta

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 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