1
I’m having a little trouble validating a form I am using ajax to validate the fields
Problem onsubmit expects a boolean kind of feedback and I’m not getting that feedback
I put a counter inside the . done(Function(html)) but that counter only works within the same when I try to retrieve the counter value out of the . done(Function(html) it is zeroed follows 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;
}
}
Set an external variable to
ajax
, but within the function and assign the value to it.– user28595