I have some AJAX, -which will load the required page every 5000ms... However, on page load, it waits 5000ms to first load it, Does anyone know a solution to make it load, -on load... and then every 5000ms after? That would be great help... Thanks alot, James Code so far: <script type="text/javascript"> function Ajax3(){ var xmlHttp; try{ xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari }catch (e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer }catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ alert("Your browser does not support this webpage sorry..."); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState == 4) { document.getElementById('ReloadTime3').innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET","live.php",true); xmlHttp.send(null); } window.onload=function(){ setInterval('Ajax3()', 5000); } </script>
Put this inside the HEAD tag: <script type="text/javascript"> function Ajax3(){ var xmlHttp; try{ xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari }catch (e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer }catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ alert("Your browser does not support this webpage sorry..."); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState == 4) { document.getElementById('ReloadTime3').innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET","live.php",true); xmlHttp.send(null); } </script> Code (markup): Add this on the BODY tag of the page: <body onload="setInterval('Ajax3()', 5000);"> Code (markup): Hope it helps.
Erm, no sorry, that doesn't work sorry, -It just loads it after 5000ms, -Like before Anyone else know how to do it? Thanks, James...
This should work. Put this Javascript in your head section: <script type="text/javascript"> function Ajax3(){ var xmlHttp; try{ xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari }catch (e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer }catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ alert("Your browser does not support this webpage sorry..."); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState == 4) { document.getElementById('ReloadTime3').innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET","live.php",true); xmlHttp.send(null); } //this will call your function every 5000ms [COLOR="red"]t=setInterval('Ajax3()', 5000);[/COLOR] } </script> Code (markup): Put this in your body tag: //this should call your function when the body loads <[COLOR="red"]body onload="Ajax3();">[/COLOR] Code (markup): Tell me if you have anymore problems. ~imozeb
Try 1st call ajax3() then setinterval() it. ... window.onload=function(){ Ajax3(); setInterval('Ajax3()', 5000); } </script> ... PHP: