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

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

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