how to use jquery or ajax to refresh a div at 10 second intervals

前端 未结 3 1983
迷失自我
迷失自我 2021-01-14 14:06

Any help at all is appreciated here folks. I\'m building a web app in php and I\'m using the Yii MVC framework which has a lot of built in tools. Just as the title says, i n

相关标签:
3条回答
  • 2021-01-14 14:27
        // zisu.php
    
        <html>
        <head>
        <script type="text/javascript">
        var auto_refresh = setInterval(
               function ()
               {
               $('#div1').load('time.php');
               }, 10000);
        </script>
        </head>
        <body>
        <div id ="div1">
        <?php
        echo date("h:i:s A");
        ?>
        </div>
        </body>
        </html>
    
    
    // time.php
        <?php
        echo date("h:i:s A");
        ?>
    
    0 讨论(0)
  • 2021-01-14 14:41

    Usin jquery

    $(function() {
        function callAjax(){
            $('#myDiv').load("http://yourdomain.com");
        }
        setInterval(callAjax, 5000 );
    });
    
    0 讨论(0)
  • 2021-01-14 14:46

    a rough equivalent to your code in jQuery is this:

    //execute call immediately
    (function check(){
        //a GET AJAX call
        $.get('protected/controllers/room/openRoom')
        .done(function(data){
            //when we receive, populate
            $('#logged_in_users_list').html(data);
        })
        .always(function(){
            //regardless of a fail or success, call again after 10 seconds
            setTimeout(check,10000);
        });
    }());
    

    and 403 will always be 403. that's the code that tells you that you are not allowed to enter that location (maybe you need authentication?)

    0 讨论(0)
提交回复
热议问题