I have a section of my sites header that has some information in it that come from the mysql database, i run a cron job every 5 mins so the content gets updated, i then want just that section in the header to be refreshed without refreshing the whole page, i have been told this can only be done using ajax, but are there any other methods to get this done?
No, just ajax (or flash). Can I ask, every 5 minutes seems really slow. Are people staying that long on the page?
The information is displayed thoughout the whole site, in the header, time spent on the site on average is 12-15 mins per user. I didnt know if something could be done using Iframe, the header page would include the iframe, the iframe would display the data, then the iframe page would refresh rather than the whole page. So there is definatly no work around? it has to be ajax or flash then?
Well yeah, you could do it via an iframe. Just place this in the iframed page (in the <head> section): <meta http-equiv="refresh" content="300" /> HTML: (60s x 5)
Thanks i have given you +REP can you tell me would that code refresh the iframe/page every 5 mins from when the page is loaded, or can you get the page to refresh every 5 mins from the server time so it would coincide with the cron update?
It's from when the page is loaded.. I suppose you could do it via javascript as well but that would depend on the user clock being set at the same time.. which usually isn't the case. (to be able to reload at 5:00, 5:05 etc) You could however write a PHP script in that iframe.. that checks the current time and calculates how many seconds until the next refresh/cron. Then just add 10 seconds to be sure the cronjob is finished. The php script will simply write a javascript variable, then you'd use javascript to count down that nr of seconds until refresh. All this is conceptual, if someone wants to they can write it in code. Or find a better way.
Its better if you simply opt for a javascript library with Ajax support, and using function setInterval(); to call the ajax function to re-load the contents. I am more in JQuery, so for that, the script shall be : function RefreshDIV(){ $('#div').load('page.html'); } setInterval("RefreshDIV()", 3000): Code (markup): you may use any other library or simply an ajax custom function like: <script type="text/javascript"> var xmlhttp; function loadXMLDoc(url) { xmlhttp=null; if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc. xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlhttp!=null) { xmlhttp.onreadystatechange=state_Change; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else { alert("Your browser does not support XMLHTTP."); } } function state_Change() { if (xmlhttp.readyState==4) {// 4 = "loaded" if (xmlhttp.status==200) {// 200 = "OK" document.getElementById('T1').innerHTML=xmlhttp.responseText; } else { alert("Problem retrieving data:" + xmlhttp.statusText); } } } </script> Code (markup): you may get a better hold of Ajax on: http://www.w3schools.com/Ajax/default.asp Code (markup):