var deferred = $.Deferred();
function doSomething() {
for (i = 1; i < 10; i++) {
context.executeQueryAsync(function () //success function
{
if (check_i_val(i)) {
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
},
function (sender, args) //failure function
{
console.log(args.get_message());
});
}
}
function success() {
console.log(i);
}
function failed() {
//display error
}
function check_i_val(val) {
if (val = 1 || val = 3 || val = 5 || val = 7) {
return true;
}
}
I want this to produce 1,3,5,7 in that order - the actual function i'm using is more complex than this and has loading times so the results are unexpected. How can I use deferred (as a jquery promise) so that my code will run sequentially?