Auto refresh body of page with JQuery

Ever want to refresh the body of a page, but not everything else (head section, etc)?

Here is how you do it…

First, we need to make sure we include the JQuery script in our page. This should be placed at the bottom, just before the body tag.

Next, we will include a quick script below the jquery.min.js call…

<script>
$(‘#reloadbtn’).focus();
$(‘#reloadbtn’).click(function() {
$.ajax({
url: “”,
context: document.body,
success: function(s,x){
$(this).html(s);
}
});
});
</script>

Finally, create a button with a ‘reloadbtn’ id somewhere in the body of your page…

<button id=”reloadbtn” >Refresh</button>

 

That’s it. You now can refresh just the body. Using this example, you can modify it to do some other cool refreshes as well. Please comment if you have modifications to this code!

Leave a Reply