Mampel Mampel - 6 months ago 8
Ajax Question

no response from ajax in when method

i have no response after call ajax method in $.when:

$.when(tht.ajax.getUserDrp()).done(function (data) {
if(data) console.log('hava data')
else console.log('no data')
});


getUserDrp function:

getUserDrp: function(){
$.ajax({
url: "../account/getLevel" ,
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
// do somthing
}
});
}


as a result always print 'no data' in console, why?

Answer

You are trying to use getUserDrp as a promise but you don't return the $.ajax function result, that's why .done() never gets called.

Try:

getUserDrp: function(){
  return $.ajax({
    url: "../account/getLevel" ,
    type: "POST",
    contentType: "application/json; charset=utf-8"
  });
}
Comments