I see no getChat text function. However, I had a similar issue with my chat app, the only way I found was to set the timeout after getting both the chat messages and the users online.
Here's the code, still a work in progress but you should get the idea:
function newGet()
{
// Get Chat Message Data
var recObj= new ajaxObject('getchatdata.php', displayChatData);
recObj.update();
// Get List of Users Currently using Chat
var usrObj = new ajaxObject('getuserlist.php', displayUserData);
usrObj.update();
//Re-Check every 2 seconds
setTimeout('newGet()',2*1000);
}
function newSend()
{
var sndObj= new ajaxObject('sendchatdata.php', displayChatData);
var userid='<?php echo $_SESSION["user_id"]?>';
var msg=document.getElementById('message').value;
if(msg.length>100){msg=msg.substring(0,100)};
var message=('user='+userid+'&message='+msg);
document.getElementById('message').value = "";
sndObj.update(message,'POST');
}
function displayChatData(responseText, responseStatus){
if(responseStatus==200)
{
var mdiv=document.getElementById('chatwindow');
if(!mdiv){return};
var messages=responseText.split('|');
// display messages
}
}
function displayUserData(responseText, responseStatus){
if(responseStatus==200)
{
var mdiv=document.getElementById('userContainer');
if(!mdiv){return};
mdiv.innerHTML='';
var messages=responseText.split('|');
// display messages
}
}
function intitializeChat()
{
if(blah blah blah)
{
newGet();
}
}
The getUserList.php file woulld have to check which users have posted in the last 2 mins. But y not display all users within the chat. Easily done, as every time you check for message and users you can write to a db file using a timestamp, all records that are older than 5 seconds are for users that have left, as we update every 2 seconds.