Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

Update Content After Certain Time using jQuery,Ajax and PHP

by
Category:php
php ajax jquery
Update Content After Certain Time using jQuery,Ajax and PHP

Some content updates may be based on time the user information for the current user, other updates may be based on requests performed by any user, such as information based on a search performed by the Web-site visitor. You may also like Mysql UPDATE Statement using Join Statement and Update Query in Laravel 5.

HTML and jQuery Code

<html>
    <head>
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </head>

    <body>
        <div id="quote_box">
            <p id="quote">Please Wait</p>
        </div>
    </body>
    <script type="text/javascript">
        $(document).ready(function() {
            $.ajaxSetup({ cache: false }); 
            setInterval(fetch_quotes,5000);
        });

        function fetch_quotes()
        {
            $.ajax({
            type: 'post',
            url: 'get_content.php',
            data: {
             get_quote:"quote"
                },
                success: function (response) {
                    document.getElementById("quote").innerHTML = '"' + response + '"';
                }
            });
        }
    </script>
      
</html>

PHP Code (get_content.php)

<?php
if (isset($_POST['get_quote'])) {
    $quote = array(
        'demo1',
        'demo2',
        'Success'
    );

    $total = count($quote) - 1;
    $var = mt_rand(0, $total);
    echo $quote[$var];
    exit();
}
?>

0 Comments


Html code work in comment box


Related Post