Javascript – is auto-refresh is possible in jquery without making the page blink?? like in facebook

asp.netfacebookjavascriptjquery

I'm having a problem about the blinking of the page for my auto-refresh of the page function. Is there a way to make my this blinking of the said page begone?
Here's my code:

<script type="text/javascript">
    function refreshPage() { location.reload(); }
    $(document).ready(function () {
       setInterval('refreshPage()', 5000);
    });
</script>

Thanks.

Best Answer

You probably don't want to refresh the entire page. E.g. logo, menu would stay, while a content somewhere will refresh. I would mark this content with e.g. a div:

<div id="content">
    <!-- stuff in here is to be periodically refreshed -->
</div>

Then, I would add a server-side URL to create just that refreshable content. This depends of course on your server-side technology, but it is probably trivial. Say this URL is http://yourserver/path/to/page/content.

Then with jQuery:

$(document).ready(function () {
    setInterval(function() {
        $("#content").load("http://yourserver/path/to/page/content");
    }, 5000);
});

This is the principle of operation, you may adjust the details. See $.load. This will greatly eliminate the blink.