I have a table with multiple records with their respective information and ids
.
When I click on a button I make a request via post and Ajax individually from that row of the table.
But I have another button that scrolls the entire table by taking their ids
and doing the requests individually.
When you have finished all the requests, you have or have not enabled a button to continue.
The problem is when to capture the last request of these records. I can not.
My code:
function calculaMedia(aluno) {
$.when( calculaMediaFuncao(aluno, function(){}) ).then(function(ret){
console.log(ret);
console.log( "Disparei assim que as requisições se completaram" );
return true;
}).fail(function(){
console.log( "Disparei se uma ou mais requisições falharam" );
return false;
});
}
function calculaMediaFuncao(aluno, callback) {
$.post( "/index.php?r=aluno%2Fnota-aluno&aluno="+aluno+"&disc="+disc+"&tipo="+tipo+"&ap="+notaAP, function( data ) {
$( "#situacaoFinal_"+aluno ).html( data );
callback( true );
}).fail(function() {
callback( false );
})
}
function calcularNotas() {
$("#btnGravarNotas").removeAttr("disabled");
$('#tabelaAlunos > tbody > tr').each(function(key, data) {
var aluno = $(data).attr('data-aluno-id');
console.log(aluno);
calculaMediaFuncao(aluno, function (res) {
if (!res) {
$("#btnGravarNotas").attr("disabled", "disabled");
}
});
});
}
Individually I call for calculaMedia(aluno)
.
But when you click a button you have to call all records and only enable the button when the last request is completed and it is true
.
Someone helps me ...