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

187
Views
encadenar funciones ajax: dónde colocar async await

aquí está el escenario:

Función btnplus : inserta algunos datos nuevos en una base de datos

llama a get_atitles , que también es una llamada ajax para llenar un div con el nuevo conjunto de datos

cuando se llena el div, go_find debería encontrar un elemento específico dentro del nuevo conjunto. esto no es un ajax

problema: go_find se inicia antes de que get_atitles finalice, por lo que no puede encontrar los datos necesarios

Intenté colocar async await en varios lugares, sin éxito

Entonces, ¿cómo llamar a go_find después de que se complete get_atitles ?

 $(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 answers
Answer question

0

Re: Entonces, ¿cómo llamar a go_find después de completar get_atitles?

Simplemente coloque la llamada a la función go_find dentro del controlador de resultados get_atitles .

 $(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` }

Alternativa

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