Forum Moderators: coopster
I am developing a instant messneger chat application.
I need to refresh a page for every 5 sec using ajax without using DIV tags.
I need to refresh the page every 5 seconds to check the DB for waiting messages, if the waiting messages exist in DB I need to popup a chat window.
If it is possible please help me....It will be appreciated.
Please give me some suggestions how to do that....
thanks in advance...
regards,
Ganesan
I have given below the javascript/ajax and php i used.
function PMstateChanged(){
if (xmlHttp.readyState==4)
{
document.getElementById("openPMbox").innerHTML=xmlHttp.responseText;
xmlHttp = null;
}
}
function openPMBox(ID) {
setInterval("PMBoxOpen('"+ID+"')", 5000 );
}
function PMBoxOpen(uID) {
xmlHttp = GetXmlHttpObject();
var url = "openPMbox.php?uID="+uID;
xmlHttp.onreadystatechange=PMstateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
Code of openPMbox.php is...
<?
ob_start();
session_start();
$uid=$_SESSION['login_user_id'];
$con=mysql_connect("localhost","root","");
mysql_select_db("sweet60");
$sql1 = "SELECT * FROM `chat_messages` WHERE touserID='".$_SESSION['userID']."' AND status='0'";
$query1 = mysql_query($sql1)or die(mysql_error());
while ($res1 = mysql_fetch_array($query1)) {
//echo "you are having pending message";
//echo $res1['sessionID'];
echo "<script language='javascript'>openChat(\"Messenger/convo.php?sessionID=".$res1['sessionID']."\", \"Convo\");</script>";
}
?>
i called the openPMBox() function in onload event. All the functions are working but it is not promt the popup window. I am strucking here ..please help me...it would be great help for me
thanks in advance....
First I'd change openChat(...) into alert('I got a message') and be sure it gets that far; if it does, I'd change it back and track from function openChat() onwards (which you didn't paste here).