Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda