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
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.