I'm having a problem with validating a form I'm using ajax to validate fields
Problem the onsubmit expects a boolean type return and I am not able to make that return
I put a counter inside the .done (function (html)) but this counter works only inside it when I try to retrieve the counter value outside .done (function (html) it is zeroed follow my code
function validaFormALterar(acao) {
var opc = acao;
var erro = 0;
var url = 'model/validarSenha.php';
var Csenha = 'Csenha=' + $('#Csenha').val();
var dados = Csenha;
$.ajax({
url: url,
data: dados,
cache: false
}).done(function (html) {
if (html == 'erro') {
//não consigo pegar o valor desse ERRO fora do DONE
erro++;
}
});
//erro sempre chegando 0
console.log("Erro nº " + erro);
if(erro==0){
return true;
}
}