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

217
Views
¿Cómo puedo crear una promesa falsa que responda con una función realizada?

Tengo este código, que no funciona si vID=0 porque ajax.done no es una función:

 if (vID > 0) { var ajax = CallPHP('GET', 'grid_main.php', "idquery=7&trkbid=" + vID); } else { // Here I need a fake ajax so that the following code will work var ajax=new Promise(); }; ajax.done(function(data, textStatus, jqXHR) { // do something }

¿Cómo puedo arreglarlo? Gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Más lógico es hacer una función y llamarla.

 function nextStep(data, textStatus, jqXHR) { // do something } if (vID > 0) { var ajax = CallPHP('GET', 'grid_main.php', "idquery=7&trkbid=" + vID).done(nextStep); } else { nextStep({}); };

No puede usar una promesa ya que el objeto Ajax de jQuery no es una promesa. Tendría que parecerse a algo

 var ajax = { done: function(method) { method({}); } }; ajax.done(function(data, textStatus, jqXHR) { console.log(data); });

Podrías usar el diferido de jQuery

 var ajax = $.Deferred().resolve({}); ajax.done(function(data, textStatus, jqXHR) { console.log(data); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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!