hello..
i want to write code for refresh only division part which is in page. why because i am fetching images from database randomly. when we refresh the page the image change randomly.
so.....i want to do refresh only division part every 1min. how to do?

You can just use a meta refresh on the page:

<meta http-equiv="refresh" content="60;url=index.php">

The other way to do it would be to use the header function of PHP and put in header('refresh: 60');

You can just use a meta refresh on the page:

<meta http-equiv="refresh" content="60;url=index.php">

The other way to do it would be to use the header function of PHP and put in header('refresh: 60');

i want to refresh only <div> . not whole page.

You can do this with AJAX and JavaScript:

# <script src="ajax/moniter/moniter.js" type="text/javascript"></script>
# <body onload="moniter();">
# <div id="moniter">
#  
#       </div>
# </body
# // JavaScript Document
# var xmlHttp_moniter
#  
# function moniter()
# {
#     xmlHttp_moniter = GetXmlHttpObject_parcel()
#     if(xmlHttp_moniter == null)
#     {
#         alert("browser does not support HTTP Request")
#         return
#     }
#     var url="ajax/moniter/moniter.php" + Math.random()
#     xmlHttp_moniter.onreadystatechange = stateChanged
#     xmlHttp_moniter.open("GET",url,true)
#     xmlHttp_moniter.send(null)
#  
# }
#  
# function stateChanged()
# {
#     if(xmlHttp_moniter.readyState==4 || xmlHttp_moniter.readyState == "complete")
#     {
#         document.getElementById("moniter").innerHTML = xmlHttp_moniter.responseText
#         setTimeout('moniter()',100);
#     }
# }
#  
# function GetXmlHttpObject_parcel()
# {
#     var xmlHttp_moniter=null;
#     try
#     {
#         xmlHttp_moniter=new XMLHttpRequest();
#     }
#     catch (e)
#          {
#              //Internet Explorer
#              try
#               {
#                   xmlHttp_moniter=new ActiveXObject("Msxml2.XMLHTTP");
#               }
#              catch (e)
#               {
#               xmlHttp_moniter=new ActiveXObject("Microsoft.XMLHTTP");
#               }
#          }
#     return xmlHttp_moniter;
# }
var url="ajax/moniter/moniter.php" + Math.random()

where s moniter.php? i am also practice same example. but no use

You will have to change the name of the scripts to what you have. That is just a code example of how to refresh a div tag.

Member Avatar for diafol

SOrry to butt in. The prototype library can ease the use of ajax objects and allow straightforward updating:

Get the prototype library from prototypejs.org and keep it in "scripts" folder.
Create the myajax.js file, also in the scripts folder.

In your page:

<head>
    ...other head elements...
    <script src="/scripts/prototype.js"></script>
    <script src="/scripts/myajax.js"></script>
    <script>var int=self.setInterval("doRefresh()",60000);</script>
</head> 

...other html...

<div id="mydiv">
   
...contents...

</div>

...other html...

Your myajax.js file:

function doRefresh(){
  var url = "/includes/newdata.php";
  var div = "mydiv";
  var oNewRefresh = new Ajax.Updater(div, url,{method: 'post'});
}

Your /includes/newdata.php file:

echo "YAH! @ " . date("H:i:s");

Obviously you'd have something a bit more useful in the php file.

The code has not been checked, so I don't know if it works, but it's not far off.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.