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

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

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