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

189
Vistas
chaining ajax functions - where to place async await

here is the scenario:

btnplus function - inserts some new data into a database

it calls get_atitles - which is also an ajax call to populate a div with the new set of data

when the div is populated - go_find should find a specific element inside the new set. This is not an ajax

problem - go_find starts before get_atitles is finished so it cannot find the required data

I tried to place async await on various places - without success

so how to call go_find after get_atitles is completed ?

$(btnplus).on('click', function(){
    ...
    $.post('pro.php', {fn: 'btn_plus_fi', args: [path]}, async function(data){
        // some new data is added to database
        await get_atitles(); // load the new set of data into a div
        go_find(str); // find a specific data inside a new set
    });
});

function get_atitles(){
    ...
    $.post('pro.php', {fn: 'get_atitles', args: [par]}, function(data){
        atitles.html(data);
    });
}

function go_find(str){
    // find something inside `atitles`
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Re: so how to call go_find after get_atitles is completed ?

Just put go_find function call inside the get_atitles result handler.

$(btnplus).on('click', function() {

  $.post('pro.php', {
    fn: 'btn_plus_fi',
    args: [path]
  }, async function(data) {
    // some new data is added to database
    await get_atitles(); // load the new set of data into a div
  });
});

function get_atitles() {

  $.post('pro.php', {
    fn: 'get_atitles',
    args: [par]
  }, function(data) {

    atitles.html(data);

    go_find(str); // find a specific data inside a new set
  });
}

function go_find(str) {
  // find something inside `atitles`
}

Alternative

$(btnplus).on('click', function () {

  $.post('pro.php', { fn: 'btn_plus_fi', args: [path] }, async function (data) {
    // some new data is added to database
    $.post('pro.php', { fn: 'get_atitles', args: [par] }, function (data) {
      atitles.html(data);
      go_find(str); // find a specific data inside a new set
    });
  });
});
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