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

226
Vistas
how can I create a fake promise that answers with a done function?

I have this code, which does not work if vID=0 because ajax.done does is not a function:

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
}

how can I fix it? Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

More logical is make a function and call that.

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({});
};

You can not use a promise since jQuery's Ajax object is not a promise. It would have to look something like

var ajax = {
  done: function(method) {
    method({});
  }
};

ajax.done(function(data, textStatus, jqXHR) {
  console.log(data);
});

You could use jQuery's deferred

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