1
I’m trying to display the incorrect data message via Ajax but I’m not getting it, what am I doing wrong? And the header is not redirecting
Ajax
$(".form_log").submit(function(){
$.ajax({
url: 'login.php',
type: 'POST',
data: $(".form_log").serialize(),
success: function(data){
$(".resp").html(data);
},
error: function(request, status, error){
$(".resp").html(error);
}
});
return false;
})
PHP
session_start();
include_once("pdo/config.php");
$conn = conexao();
if(empty($_POST['user'])){
echo '<span class="msg error">preencha seu login</span>';
}elseif(empty($_POST['pass'])){
echo '<span class="msg error">preencha sua senha</span>';
}else{
$user = $_POST['user'];
$pass = $_POST['pass'];
$log = $conn->prepare("SELECT * FROM `login` WHERE user = '$user' AND pass = '$pass'");
$log->execute();
$count_log = $log->rowCount();
if($count_log >=1){
$row_log = $log->fetchAll(PDO::FETCH_OBJ);
foreach($row_log AS $list_log){
$_SESSION['nome'] = $list_log->nome;
$_SESSION['sobrenome'] = $list_log->sobrenome;
$_SESSION['email'] = $list_log->email;
$_SESSION['user'] = $list_log->user;
$_SESSION['captcha'] = $list_log->captcha;
header("refresh: 3; bem-vindo.php");
echo '<span class="msg success">aguarde...</span>';
}
}else{
echo '<span class="msg error">dados incorretos</span>';
}
}
just out of curiosity of my own, why did you use setTimeout to redirect only 3s dps?
– Will
Hi @Will. It was because of
refresh: 3;
that he was using onheader
.– Sam