Reload Page Content Using Jquery

This snippet to reload a page content, using Jquery within interval time (in second). This is suitable to be applied on realtime data display.

<!DOCTYPE html>
<html>
<head>
<title>Reload Content</title>

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script>
$(document).ready(function () {
    setInterval(function() {
        $.get("file-to-be-reloaded.php", function (result) {
            $('#reload').html(result);
        });
    }, 1000);
});

</script>
</head>

<body>
    <div id = "reload"></div>

    
</body>
</html>

ps:

  1. 1000 mean 1 second.
  2. As mentioned on this official jquery, is advised to download jsquery-latest.js rather then on CDN
Share to

Do You Know!