Pages

Monday 13 October 2014

Reload DIV section in Webpage without refreshing whole page

In a website without refreshing the whole page we can reload the specified div section only. The php and JQuery code as follows..

To run this code you need XAMPP or WAMP server.

index.php:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <!-- <META HTTP-EQUIV="refresh" CONTENT="15">-->
        <title>MySQL Example</title>
        <script src="http://code.jquery.com/jquery-latest.js">
        </script> 
        <script>
            $(document).ready(
                    function() {
                        setInterval(function() {
                            $('#body1').load('index.php' + ' #body1');
                        }, 5000);
                    });
            $(document).ready(
                    function() {
                        setInterval(function() {
                            $('#body2').load('index.php' + ' #body2');
                        }, 1000);
                    });

        </script>                     

    </head>
    <body>
        <?php
        // put your code here

        date_default_timezone_set('Asia/Calcutta');

        echo "<div id='body1'>Now Lucky Draw Number is: " . rand(1, 1000) . "</div>";
        ?>

        <div id="body2">Time: <?php echo date('d-M-Y H:i:s'); ?>
           
        </div>

    </body>
</html>

No comments:

Post a Comment