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!