Hy guys, I have a problem with async call in ajax jquery. This is my code:
$(document).on('click', '#search', function () {
$.get(context + '/AjaxGetIvaNoleggio', function (data) {
iva = (data / 100) + 1;
});
cont = 0;
var dataDal = $('#dataDal').val();
var dataAl = $('#dataAl').val();
$.get(context + '/AjaxRendimento?tipoUtente=-1&dataDal=' + dataDal + '&dataAl=' + dataAl + "&all=" + all, getAll).done(
$.get(context + '/AjaxRendimento?tipoUtente=0&dataDal=' + dataDal + '&dataAl=' + dataAl + "&all=" + all, getAll).done(
$.get(context + '/AjaxRendimento?tipoUtente=1&dataDal=' + dataDal + '&dataAl=' + dataAl + "&all=" + all, getAll).done(
$.get(context + '/AjaxRendimento?tipoUtente=3&dataDal=' + dataDal + '&dataAl=' + dataAl + "&all=" + all, getAll))));
});
const getAll = function (data) {
var numNoleggio = 0;
var imponibile = 0;
var iva = 0;
var tot = 0;
var table = '<table class="table table-bordered table-striped tableData ">n'
+ '<tr>';
if (cont === 0) {
table += '<th colspan="4" class="text-center">ALL</th>';
} else if (cont === 1) {
table += '<th colspan="4" class="text-center">USER</th>';
} else if (cont === 2) {
table += '<th colspan="4" class="text-center">AGENCY</th>';
} else if (cont === 3) {
table += '<th colspan="4" class="text-center">ADMIN</th>';
}
//here I iterate the data
table += //here create the table with datas in data;
$('.rendiconto').append(table);
cont++;
};
I tried with done, after and then but the results are not in order, how can I do it?
I want the first call in cont ===0
, the second call in cont ===1
, the third call in cont ===2
and the fourth call in cont===3
.