1
var erroEnvio = false; //global
$(".proxima-questao").on("click",function(){
$(".loading").show();
$.ajax({
url: urlBase+"123123123/adasdasdasdas",
type: "POST",
data: $("#form").serialize(),
success:function(resposta){
if(resposta === "sucesso"){
erroEnvio = false;
setSuccessEnvio(erroEnvio);
$(".loading").hide();
} else {
erroEnvio = true;
setSuccessEnvio(erroEnvio);
$(".loading").hide();
}
}
});
});
function setSuccessEnvio(x){
erroEnvio = x;
}
if(erroEnvio === false) {
// a idéia é salvar os dados antes de ir pro próximo bloco
proximaQuestao();
} else {
alert("Erro");
}
if($stmt->execute()){
return "sucesso";
} else {
return "falha";
}
one thing I noticed is that it’s returning success even with the dropped connection.
When I get offline, I can go to the next question, after I’m on the next block, if I click again on botão próxima questão
it shows this Error alert.
Because you have
setSuccessEnvio
if its change in theerroEnvio
is already going global?– Guilherme Lautert
No need to test before sending. You send and see if it worked for the return of Ajax, and take the necessary action based on this.
– Bacco