0
I created 3 functions, where each one makes a request ajax
- The first:
checkFila()
check if there are any outstanding schedules, if yes, call the second. - The second:
sendEmail()
send the email that is in line and the success of it, call the third. - The third:
limpaFila()
responsible for cleaning up.
The problem is that the second and third functions are not performed. I searched on the subject and saw that it is necessary to use deferred
/ when
but I don’t know how.
function checkFila() {
$.ajax({
type: "GET",
url: "checkFila.php",
async: false,
dataType: "json",
success: function(data) {
var statusRetorno = data.retorno;
var idAgendamento = data.idAgendamento;
sendEmail(idAgendamento);
if (statusRetorno) {
//if( !( typeof idTimerCheckFila=="undefined" ))
//clearInterval( idTimerCheckFila ); // limpa o timer
// reinicializar timer
//idTimerCheckFila = setInterval( function(){ checkFila(); }, 120000 );
}
},
error: function() {
bootbox.alert("Falha de Conexão!<br />Não foi possível efetuar sua requisição.<br/>Aguarde alguns instantes e faça uma nova tentativa.");
}
});
};
function sendEmail(numID) {
$.ajax({
type: "GET",
url: "sendEmail.php=" + id_agendamento,
dataType: "json",
success: function(data) {
var statusRetorno = data.retorno;
if (statusRetorno) {
table_fila_emails.ajax.reload();
limpaFila();
}
},
error: function() {
bootbox.alert("Falha de Conexão!<br />Não foi possível efetuar sua requisição.<br/>Aguarde alguns instantes e faça uma nova tentativa.");
}
});
};
function limpaFila() {
$.ajax({
type: "GET",
url: "clearFila.php",
dataType: "json",
success: function(data) {
var statusRetorno = data.retorno;
if (statusRetorno)
table_fila_emails.ajax.reload();
},
error: function() {
bootbox.alert("Falha de Conexão!<br />Não foi possível efetuar sua requisição.<br/>Aguarde alguns instantes e faça uma nova tentativa.");
}
});
};
Welcome to [en.so] Francisco! First of all I suggest to you, how to create a [Mre] to be able to elaborate a good question, because it lacks information! So have you considered trying to look at your browser console to verify which error is returned? without using deferred/when?
– gleisin-dev
Note that you can debug your code, going through it step-by-step, each function, each step, etc. Ex:
success: function(data) { console.log ("cheguei aqui!"); ... }
and so on!– gleisin-dev
I understand your considerations but it is by the browser console that I saw that only the first function, checkFila() is executed. I just forgot to mention that this function is run every 2 minutes by the setinterval time event().
– Francisco Marcelo Pereira