1
Personal I am wanting to enable a button only when the last post request via Ajax is executed successfully.
I have a table with several records with their respective information and ids
.
By clicking a button I make a request via post and individual Ajax of this table row.
But I have another button that runs through the entire table picking up their respective ids
and making the requests individually.
When finishing all requests is that enable or not a button to continue.
The problem is when to capture the last request of these records. I’m not getting.
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 the records and only enable the button when the last request is completed and is true
.
Somebody help me...
You’ll get better answers if you give people code they can use to reproduce the problem.
– user60252