I would like to know how to compare a session
of a page php
with ajax
for the simple reason to display a alert
more beautiful to the client the comparison that I have and the following it compares not part in php
if there is a user logged in if it does not exist the message of alert
has how do I do this with ajax
? to simply change the alert
?
This and the code php
that does the verification is at the top of the page that is called when I click on Buy:
if ( ! isset( $_SESSION ) || ! isset( $_SESSION['clienteSession'] ) || $_SESSION['clienteSession'] != true )
{
echo "<script type=\"text/javascript\">
alert(\"Você Precisa estar Logado para Efetuar a Compra!\");
window.location='login.php';
</script>";
}
Result:
if (!isset( $_SESSION ) || !isset( $_SESSION['clienteSession'] ) || $_SESSION['clienteSession'] != true ){
echo "nao logado";
}
part js:
$("#comprar").click(function(){
$.ajax("carrinho.php",{
}).done(function(r){
if(r == "nao logado"){
alertify.error("Você Precisa estar Logado para ter Acesso a Esta Página");
setTimeout("window.location=login.php",2000);
return;
}
}).fail(function(){
alertify.error("Opss Algo deu Errado");
})
});