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

127
Views
Create POST request before redirect

The goal is when a user visits the index route/ the JS code should create the post request then redirect to another url given by flask webapp

but when i uncomment i still get redirected but no post request is begin made

how do you redirect after the post request

A simple js function to check user info

<script type="text/javascript">
    function lookup() {
    const URL = '/route';
    const xhr = new XMLHttpRequest();

    $.get('https://www.cloudflare.com/cdn-cgi/trace', function(data) {
      data = data.trim().split('\n').reduce(function(obj, pair) {pair = pair.split('=');
        return obj[pair[0]] = pair[1], obj;
      }, {});
      sender = JSON.stringify(data) 
      xhr.open('POST', URL);
      xhr.send(sender);
      //console.log(data);
      });
    }
</script>

<body onload="lookup()"> </body>

<script type="text/javascript" > window.location.href = '{{x}}' ; </script>

Flask route


@UI.route('/' )
def index():
    if request.method == "POST":
        return render_template('index.html')
    else: 
        return render_template('index.html')
about 4 years ago · Juan Pablo Isaza
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!