ajax
already returns a deferred, so you could just use that. Can you change getMyData
to return the deferred that ajax
returns?
function getMyData() {
return ajax({
// ajax params
});
}
function dothis() {
// return deferred which comes from ajax
return object.getMyData(x,y,successCallback,failureCallback);
}
dothis().done(function(){
// do something on success
}).fail(function(){
// do something on failure
});
If you can't change getMyData
to return the deferred, you can do this:
function dothis() {
var dfd = $.Deferred();
object.getMyData(x,y,function(){
dfd.resolve(); // success
},function(){
dfd.reject(); // fail
});
return dfd.promise();
}
dothis().done(function(){
// do something on success
}).fail(function(){
// do something on failure
});