I have looked into many solutions which uses deffered and promises.Tried those solutions in my scenario but couldn’t got a solution.I have been fighting with through out the entire day.My scenario is.
I have array of customers.And i need to do some certain actions to each customer one by one which are defined as ajax.
private function main()
{
customers=["customer1","customer2"]
customers.forEach(function(customer) {
function1();
function2();
function3();
}
}
private function function1()
{
$.ajax({
type: "POST",
url: Url1,
data: {},
success: function (data) {
console.log("a");
},
dataType: 'JSON'
});
}
private function function2()
{
$.ajax({
type: "POST",
url: Url2,
data: {},
success: function (data) {
console.log("b");
},
dataType: 'JSON'
});
}
private function function3()
{
$.ajax({
type: "POST",
url: Url3,
data: {},
success: function (data) {
console.log("c");
},
dataType: 'JSON'
});
}
When the main function is called .My desired output is
a
b
c
a
b
c
But the output i am getting is
a
a
b
b
c
c
Please help me find a solution.
2
Answers
Finally i solved my issue by making a recursive function call without using loop.
And current output is
Ajax call by default is the async. action.