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

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

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