Hi All, I need to update data dynamically without reloading the page each and every time, data will be getting for every 10 seconds. Please help with jquery code.
You can use the jquery load() function which allow you to refresh the content of a div without refreshing the entire page, and the delay() function to refresh the div every 10 seconds. Let say you have your html page index.html, inside this page a div 'mydiv' with your data you want to refresh, and a php page 'page.php' to manipulate your data, so you could do something like: <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $('#mydiv').delay(10000).load('page.php'); }); </script> </head> <body> <div id="mydiv"></div> <body> </html> Code (markup): Not sure if it will refresh every 10 seconds, or just one time after 10 seconds, as I didn't try it, but if you modify it, maybe with a setTimeout("myfunction()", 10000), it might work.
Hi wab, Thanks for the reply, i tried, but if load the page.php in mydiv the whole page with header and footer are loading into the mydiv, i need only the content to be loaded.
if your page.php is only a function accessing a database for example, and building a table around your data, so only this table will be sent to mydiv. That will work perfectly if mydiv is only the container of the content you want to refresh every 10 second and if page.php is used only for your data.
How about this. $(document).ready(function(){ setInterval(function(){ $.get("page.php", function(data){ $("#header").html(data); }); }, 10000); });
hi, you might want to use this $(document).ready(function(){ setInterval(function(){ $("#header").load('page.php #content_div'); }, 10000); }); PHP: where #content_div is the thing you only want to display
here's the solution I've applied on one site (adapted, mine was using link click as a trigger): setInterval(function(){ var $container = $('#container'); var url = 'your_url_to_load_data'; // must return html, even if you type the url in address bar of your browser $.ajax(url).done(function(response){ $container.html(response); }); }, 10000); Code (Javascript):