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

86
Views
How to delay one of the 3 ajax calls?

I need help with these AJAX forms. I need the smallest one to be executed after the others and I want to delay that.

I tried to use setTimeout(), but it seems to not work for me.

I need that because the smaller AJAX with overalleff.php is making calculations from the other two AJAX requests.

// THIS IS THE AJAX FOR THAT I WANT TO DELAY
// THIS AJAX NEED TO BE EXECUTED AFTER OTHERS
function pbutton() {
  $.ajax({
    url: "overalleff.php",
    success: function(data) {
      setTimeout(function() {
        $data
      }, 2000);
    }
  });
}

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: "pickingeff.php",
      data: {
        fromdate: varies,
        todate: varies2
      }
    }).done(function(msg) {});
  }
}

var sarray = [];

function abutton() {
  var varies3 = $("#fromdate").val();
  var varies4 = $("#todate").val();
  if (varies3 == "" || varies4 == "") {
    alert("Please fill in all 2 fields first and then submit again");
  } else {
    sarray.push(varies3 + "~" + varies4);
    $('#loadingmessage').show();
    $.ajax({
      type: "POST",
      url: "packingeff.php",
      data: {
        fromdate: varies3,
        todate: varies4
      }
    }).done(function(msg) {
      $('#loadingmessage').hide();
    });
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since $.ajax returns a Promise, you can use Promise.all which runs a function after all other promises are over.

function makeThreeAjaxCalls() {
    let p1 = $.ajax("url1");
    let p2 = $.ajax("url2");
    p1.then(callback1)
    p2.then(callback2)
    Promise.all([p1,p2]).then(function() {
        $.ajax("url3").then(callback3);
    });
}
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!