First we will make a customize function called getRefresh() -
function getRefresh(){
$(“#auto”).load(“data.php”, ”, callback);
}
Here we have used load( url, [data], [callback] ) ajax api. This api load HTML output from a remote file (data.php) and inject it into the div (auto). Below we have created a callback function named callback() -
function callback(){
setTimeout(“getRefresh();”, 1000);
}
setTimeout() function is used to call getRefresh() after a specified number of milliseconds (1000). Now we can add some jquery effect to realize that the div is refreshing automatically
function getRefresh(){
$(“#auto”).fadeIn(“slow”);
$(“#auto”).load(“data.php”, ”, callback);
}
function callback(){
$(“#auto”).fadeOut(“slow”);
setTimeout(“getRefresh();”, 1000);
}
After all below is out complete code both for jquery and server scripting language -
// for jquery html
<html>
<head>
<script src=”http://code.jquery.com/jquery-latest.js”></script>
<script type=”text/javascript”>
function getRefresh() {
$(“#auto”).fadeIn(“slow”);
$(“#auto”).load(“data.php”, ”, callback);
}
function callback() {
$(“#auto”).fadeOut(“slow”);
setTimeout(“getRefresh();”, 1000);
}
$(document).ready(getRefresh);
</script>
</head>
<body>
<h1>Auto refresh div by jquery</h1>
<div id=”auto”>
Random text goes here
</div>
</body>
</html>
// for php server scripting language
// data.php
<?php
mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“dbname”);
$result = mysql_query(“select * from tblname”);
while ($row = mysql_fetch_object($result)) {
echo $row->username.’<br/>’;
}
mysql_free_result($result);
?>
Tags: auto refresh by jquery, auto refresh div, freelancer, Jquery, jquery ajax, jquery expert, jquery freelancer, jquery programmer, php freelancer, php programmer, programmer, refresh div, shahriat, shahriat hossain, shahriat hossain somel, somel, web application developer, web developer
March 19, 2009 at 6:25 pm
G8 post by @shahriat, really helpful!
April 11, 2009 at 11:36 pm
I’m new to this blog. Apologize for asking this though, but to OP…
Do you know if this can be true;
http://www.bluestickers.info/ringtones.php ?
it came off http://ringtonecarrier.com
Thanks
April 12, 2009 at 5:58 am
please tell me again the name of the javascript function that can make rectangle to roundrectangle ?
April 12, 2009 at 10:10 am
It’s better if you use image to make any div round corner because javascript depend on browser and if anybody disable the javascript from their browser then your expected round corner will not be effected. Here is a tutorial from alistapart site and going through with this article you will get your answer
http://www.alistapart.com/articles/customcorners/
July 27, 2009 at 3:10 pm
somel monay koro amar ekta input box asay html a otay ID dia search koray data antay hoy onno aro duita textbox manay html a input box a then ki koray ana possible ?