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