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

263
Views
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 answers
Answer question

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