if isset SESSION display div
How do i d开发者_Python百科o in jquery, to check if there's anything in isset SESSION user_message, each 1 seconds, and if there is then display #box else dont.. thanks
PHP file (session.php):
<?php if( isset($_SESSION) ){echo 1;}?>
JS file:
function checkSession(){
$.ajax({url: "session.php", success: function(data){
if( data == 1){
$('#box').show();
}else{
$('#box').hide();
}
}});
}
setInterval('checkSession()',1000);
This is untested, but it should do what you're looking for. Note that, typically, AJAX request expect XML or JSON, so you can reformat the session.php
file the way you want.
Use PHP to echo the jQuery command:
if (isset($_SESSION['user_message'])) {
echo '<script> $("#box").… </script>';
}
This will only echo the following if $_SESSION['user_message']
is set:
<script> $("#box").… </script>
Simple as this:
<?php
if (isset($_SESSION['user_message']))
{
?>
<script>
$('#box').show(2000);
</script>
<?php
}
?>
Or you can use fadeIn
or fadeOut
with specified time.
<?php if (isset($_SESSION['user_message'])) { ?>
<script type="text/javasscript">
$("#box").show(1000);
</script>
<?php } ?>
精彩评论