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

196
Views
¿Cómo POST redirigir a una nueva URL de Ajax en caso de éxito?

tengo este codigo:

 $.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>'; }, });

Tengo una ruta en mi matraz backend /pro_account que solo debe aceptar solicitudes POST, por lo que en el código anterior no puedo usar window.location.href = "/pro_account"; success

¿Cómo cambio esta parte (o el código completo) para realizar una solicitud de publicación en caso de éxito para redirigir a la URL /pro_account ?

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

0

Gracias a @Xupitan por indicarme la dirección correcta. De hecho, utilicé esta respuesta al final: https://stackoverflow.com/a/9252533/16673529

Código resultante:

 $.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);

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