I have a 2 functions which should call one after the other Like below.
MainFunc().then(DrawChart());
MainFunc() function internally have nested functions like I have mentioned below.
I want MainFuc() to return promise or in other way DrawChart() function should call once the createMultiBatchDropdown() is completed.
I checked some links : Nesting asynchronous jquery promises But I dont want to use any set timeout or delay functions.
I'm new to the concept of this then() and promise() function.Any help will be appreciated.
function MainFunc(){
var r = $.Deferred();
var xhr = BatchTypeFilterList(data,id).then(function(res){
//Logic goes here
var impactXhr = GetImpactData(id).then(function(result){
var DropXhr = createMultiBatchDropdown('ImpactBatchSearch',result)
})
})
return r.promise(xhr);
}
function BatchTypeFilterList(){
var deferred = $.Deferred();
var xhr = $.ajax({
//Ajax Call
success:function(result){
deferred.resolve(result);
}
})
return deferred.promise(xhr);
}
function GetImpactData(){
var deferred = $.Deferred();
var xhr = $.ajax({
//Ajax Call
success:function(result){
deferred.resolve(result);
}
})
return deferred.promise(xhr);
}
function createMultiBatchDropdown(){
var batchDropDownDeferred = $.Deferred();
//No ajax call normal jquery logic to form dropdown
batchDropDownDeferred.resolve(data);
return batchDropDownDeferred.promise(xhr);
}