-1
would like to know how do I compare a session
one-page php
with the ajax
for the simple reason of displaying a alert
most beautiful to the client the comparison I have and the following he compares not part in php
if there is a logged-in user if there is no logged-in user alert
has how I do it with the ajax
? to simply change the alert
?
this and the code php
checking this at the top of the page which is called when I click to 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>";
}
Upshot:
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");
})
});
? I know he sure want to know how I do by requisicao ajax this to Voce read my question? there is written that I want to know how to do for when click on the button buy it send the ajax to that page that contains this code snippet and AJAX do the check if you are logged in
– Leonardo Costa
Alert is never "cute". If you are using PHP, show the message on the screen in a non-intrusive way. The user experience gets better, and your work gets a more professional face. In fact, almost every time someone calls JS from inside PHP, it is a sign of problem in the use of the tools.
– Bacco
know la cara not like very much the standard Alert gets
este site diz
not cool. but has how to do what I want @Bacco ?– Leonardo Costa
instead of Alert, you can display the data in a DIV on the page, and with CSS make it very presentable.
– Bacco