开发者

if isset SESSION display div

开发者 https://www.devze.com 2022-12-21 02:19 出处:网络
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..

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 } ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号