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

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

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