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

129
Views
Llamar a una función después de que se complete la función anterior

Tengo el siguiente código JavaScript:

 $('a.button').click(function(){ if (condition == 'true'){ function1(someVariable); function2(someOtherVariable); } else { doThis(someVariable); } });

¿Cómo puedo asegurarme de que se llame a la function2 2 solo después de que se haya completado la function1 1?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Especifique una devolución de llamada anónima y haga que function1 la acepte:

 $('a.button').click(function(){ if (condition == 'true'){ function1(someVariable, function() { function2(someOtherVariable); }); } else { doThis(someVariable); } }); function function1(param, callback) { ...do stuff callback(); }
over 4 years ago · Santiago Trujillo Report

0

Si está usando jQuery 1.5, puede usar el nuevo patrón Deferreds:

 $('a.button').click(function(){ if(condition == 'true'){ $.when(function1()).then(function2()); } else { doThis(someVariable); } });

Editar: enlace de blog actualizado:

Rebecca Murphy escribió un excelente artículo sobre esto aquí: http://rmurphey.com/blog/2010/12/25/deferreds-coming-to-jquery/

over 4 years ago · Santiago Trujillo Report

0

Prueba esto :

 function method1(){ // some code } function method2(){ // some code } $.ajax({ url:method1(), success:function(){ method2(); } })
over 4 years ago · Santiago Trujillo 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!