sdevaney Posted February 20, 2009 Share Posted February 20, 2009 This is my first forey into AJAX and I am trying to get this chat script to auto refresh every 10 secs. I made this my ajax.php so I could use it on all my pages where my chat is also an include so I am not completely sure if that is the problem or not. <script>src="ajax.js" id="$ReloadThis"</script> <?php $ReloadThis=("./system/chatter.php"); include ("./system/chatter.php"); ?> Here is my ajax.js file: <script type="text/javascript"> function Ajax(){ 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 AJAX please upgrade!"); return false; } } } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4){ document.getElementById('$ReloadThis').innerHTML=xmlHttp.responseText; setTimeout('Ajax()',10000); } } xmlHttp.open("GET","http://deltoria.com/system/chatter.php",true); xmlHttp.send(null); } window.onload=function(){ setTimeout('Ajax()',10000); } </script> My problem is it displays the chat like it should but it doesnt auto refresh every 10 seconds. Any help is appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/146069-getting-ajax-to-auto-refresh-chat/ Share on other sites More sharing options...
dpacmittal Posted March 13, 2009 Share Posted March 13, 2009 try removing setTimeout('Ajax()',10000); after document.getElementById('$ReloadThis').innerHTML=xmlHttp.responseText; and change setTimeout('Ajax()',10000) in window.onload function to: setInterval("Ajax()",10000); Link to comment https://forums.phpfreaks.com/topic/146069-getting-ajax-to-auto-refresh-chat/#findComment-783725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.