Auto refreshing the content without reloading page, using JQuery
February 6, 2010 10 Comments
In my previous post I have given some tips to select multiple rows from a database table. Now we can import that page into a div, so that we can refresh the content of div without reloading the page (or you can create your own JSP page which content may dynamically change). In result, if the database content get change the page will auto refresh to get reload the changes.
For that we have JQuery framework, which you can download from here. And adding the below function of database we can reload the target JSP file in a DIV in every given time interval.
<html>
<head>
<Title>Just A Test</Title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_me').load('showdata.jsp').fadeIn("slow");
}, 10000); // autorefresh the content of the div after
//every 10000 milliseconds(10sec)
</script>
</head>
<body>
<div id="load_me"> <%@ include file="showdata.jsp" %></div>
</body>
</html>

Would this basically allow me to place a mp3 player in the footer that wouldn’t cause the page to reload upon clicking any link on the page?
Why not, actually MP3 will resides on server and you have to only load the url of the MP3 using this. As new URL of MP3 get re-loaded, it should play in you player.
Couldn’t tell why, because i’m unfamiliar with <% stuff, but the string starting with <% doesn't work… It simply prints the text itself but doesnt seem to do what it has to… Any additionnal tips sir?
hello metthieu,
are you placing these files in webserver??
actually <% %> is an JSP Scriptlet. to compile this tag you must place file in webserver.
Its really a good post.thnaks
Hi…This article helped me a lot. Thanks…
Thank You. it’s very helpful for me…
hello thank you.very much for its working…..strongly………..
where is the showdata.jsp file……..
itzzz just auto refreshing the page but not updating the status from database . can u help me?