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

269
Vistas
How to refresh AJAX form with delay after submit?

I have an Ajax for which I want to submit, but after been submitted to delay it with 4 seconds. (because Ii have PHP files that need time to calculate).

It will be perfect if you tell me how to put loading bar and where exactly. I guess its have to be after function (msg) .

I try to delay setTimeout(cbutton, 4000); but nothing happens ..

var barray = [];

function cbutton() {
  $('input:radio[name="cheking"]:checked').val();
  var varies = $("#fromdate").val();
  var varies2 = $("#todate").val();
  if (varies == "" || varies2 == "") {
    alert("Please fill in all 2 fields first and then submit again");
  } else {
    barray.push(varies + "~" + varies2);
    $.ajax({
      type: "POST",
      url: $('input:radio[name="cheking"]:checked').val(),
      data: {
        fromdate: varies,
        todate: varies2
      }
    }).done(function(msg) {
      setTimeout(cbutton, 4000);
    });
  }

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are calling recursion here, cbutton is calling itself when ajax returns success.

You need something like this

var barray = [];
function cbutton() {
    $('input:radio[name="cheking"]:checked').val();
    var varies = $("#fromdate").val();
    var varies2 = $("#todate").val();
    if (varies == "" || varies2 == "") {
        alert("Please fill in all 2 fields first and then submit again");
    } else {
        barray.push(varies + "~" + varies2);
        $.ajax({
            type: "POST",
            url: $('input:radio[name="cheking"]:checked').val(),
            data: { fromdate: varies, todate: varies2 }
        }).done(function (msg) {
            setTimeout(clearForm(), 4000);
        });
    }
}
clearForm = () => {
     $('form.input').forEach(i, input) => { $(input).val('') });
}
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