I understand the problem but I don't know how to solve it.
I'm not much familiar with Ajax. Please can anyone help me?
Let me know if you need more explanation.
Thanks.
Here is my code :
var d = moment(Date.now()).format('YYYY-MM-DD hh:mm:ss');
$.when.apply($, $.map(Object.keys(filtres), function(f) {
var query = $.ajax({
type: "POST",
url: "DB.php",
data : {
func: "getDateNextMilestone",
typeMilestione: f,
lab: lab,
labelCurrent: filtres[f]
},
dataType: "json"
});
query.done(function(data){
data.forEach(function(a,i){
if (a.borneSup != null){
if(moment(a.borneSup)<moment(d)){
d = moment(a.borneSup).format('YYYY-MM-DD hh:mm:ss');
}
}
});
}).fail(function (a, b) {
console.log(b)
});
})).done(function() {
alert("done :"+d);
});
call your synchrous loop in "done" section like this:
...
})).done(function() {
//alert("done :"+d);
*loop or function with final value (in this case d) *
});