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

207
Views
How to POST redirect to a new URL from Ajax on Success?

I have this code:

$.ajax({
    type: "POST",
    url: "/pro_signup",
    data: { data: data, key: key },
    dataType: "json",
    success: function (response) {
      document.getElementById("purchase").innerHTML =
        '<button class="btn btn-primary button-connected">Verifying...</button><p class="grey-text">Waiting for verification...</p>';
      window.location.href = "/pro_account";
    },
    error: function (exception) {
      document.getElementById("purchase").innerHTML =
        '<button class="btn btn-primary button-error">Failed</button><p class="grey-text">Verification has failed.</p>';
    },
  });

I have a route in my flask backend /pro_account that must only accept POST requests, so in success in the code above I cannot use window.location.href = "/pro_account";

How do I change this part (or the entire code) to make a post request on success to redirect to the /pro_account URL?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thanks to @Xupitan for pointing me in the right direction. I actually used this answer in the end: https://stackoverflow.com/a/9252533/16673529

Resulting code:

$.ajax({
        type: "POST",
        url: "/pro_signup",
        data: { data: data, key: key },
        dataType: "json",
        success: function (response) {
          //console.log(response);
          $("#var1").val(response);
          $("#form").submit();
        },
        error: function (exception) {
          document.getElementById("purchase").innerHTML =
            '<button class="btn btn-primary button-error">Failed</button><p class="grey-text">Verification has failed.</p>';
          //console.log(response);

with this HTML:

<form style="display: none" action="/pro_account" method="POST" id="form">
      <input type="hidden" id="var1" name="var1" value="" />
    </form>
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!