Jump to content

Getting ajax to auto refresh chat


sdevaney

Recommended Posts

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

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.