0
Good night, Personal to with a problem here, to using an ajax code to check if a Cpf is already registered without the refresh in the page not to lose the data, and returning a string with a value encrypted in sha1 for comparison and know if there is already register with Cpf in the bank, but ajax can’t compare the string, and if I from Alert in the result it prints the result variable right from php, I already searched and in American forums said it was only put $.Trim() but it didn’t help either, If anyone can help me or suggest anything, I’d appreciate it. The codes:
Ajax:
function VerificaCPF(strCPF)
{
$.ajax({
type: 'post',
url: 'daoAssociado.php',
data: {action: 'VerificaCPF', cpf: strCPF},
success: function(resultado)
{
if(resultado == '88e9d785061a31f8bae950b8e231f40426b5496c')
{
return false;
}
else if (resultado == '4b2c518cb740685b1b29f477283165b732651f05')
{
return true;
}
}
});
}
php:
if(isset($_POST['action']) && !empty(($_POST['action'])))
{
$action = $_POST['action'];
switch($action)
{
case 'VerificaCPF':
consultarCPF($conectar);
break;
case 'VerificaUsuario':
consultarUsuario($conectar);
break;
}
}
function consultarCPF($conectar)
{
$cpf = sha1($_POST['cpf']);
$queryVerificarCpf = "exec usp_verificarExistenciaCpf @cpf = ?";
$parameterVerificarCpf = array($cpf);
$query_Resultado = sqlsrv_query($conectar, $queryVerificarCpf, $parameterVerificarCpf) or die(header("Location:erronobanco.php"));
$array_Resultado = sqlsrv_fetch_array($query_Resultado);
$totalDeCpf = $array_Resultado['total'];
if($totalDeCpf != 0)
{
echo '88e9d785061a31f8bae950b8e231f40426b5496c';
}
else
{
echo '4b2c518cb740685b1b29f477283165b732651f05';
}
}
Thanks, I noticed yesterday also that the problem was in the return it was not returning so I changed the sequence of verification and stopped returning true or false to an If and put it in there direct
– Filipe