this is my problem. I have this code that allows me to check via ajax call if the "oldPsw" value is already present in the database. Based on the result, the internal control updates the input and error field cssrelative. And all this works well.
var errOld = 0;
var oldPsw = $('#oldPsw').val();
$.ajax({
url: "js/psw.php",
data: {'psw': oldPsw, 'user': user},
type: "GET",
success:function(data){
var ctrl_oldPsw = jQuery.parseJSON(data);
div = $('#oldPsw').parent();
if ( oldPsw.length === 0 ) { // empty value
div.find('#oldPsw').removeClass().addClass('error');
div.find('.icon-check').html('<i class="far fa-times-circle"></i>');
div.find('.span-error').html('Campo obbligatorio').removeClass('hidden');
errOld = 1;
} else if ( ctrl_oldPsw.check == 'false' ) { // old psw don't matches
div.find('#oldPsw').removeClass().addClass('error');
div.find('.icon-check').html('<i class="far fa-times-circle"></i>');
div.find('.span-error').html('Inserire la password attuale').removeClass('hidden');
errOld = 1;
} else { // psw matches
div.find('#oldPsw').removeClass().addClass('correct');
div.find('.icon-check').html('<i class="far fa-check-circle"></i>');
div.find('.span-error').addClass('hidden');
}
}
})
My problem is that the variable "errOld" instead does not update its value. It should return 0 in case the password matches or go to 1 in case of error, but it always returns only 0 even if the code next to it works.
Can you tell me what escapes me?
PS. I specify that it does not update the variable, in fact if at the first statement I do not give value it returns "undefined"