//接收window.opne传递过来的用户名
$username_chat = $_GET['username_chat'];
//获取loginuser
session_start();
$loginuser = $_SESSION['loginuser']
?>
window.resizeTo(800,700);
//设置隔一段时间自动取数据
window.setInterval("getMessage()", 3000);
var xmlHttpRequest;
function getMessage(){
xmlHttpRequest = getXmlHttpObject();
if(xmlHttpRequest){
var url = "getMessageController.php";
var data = "getter=<?php echo $loginuser;?>"+"&sender=<?php echo $username_chat; ?>";
xmlHttpRequest.open("post", url, true);
xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttpRequest.onreadystatechange=function(){
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
var meses = xmlHttpRequest.responseXML.getElementsByTagName("mes");
if(meses.length > 0){
for(var i=0; i
$("return_con").value += meses[i].childNodes[1].childNodes[0].nodeValue+"对你说:"
+meses[i].childNodes[3].childNodes[0].nodeValue+" ["+meses[i].childNodes[4].childNodes[0].nodeValue +"]\r\n";
}
}
}
}
};
xmlHttpRequest.send(data);
}
}
function sendMessage(){
xmlHttpRequest = getXmlHttpObject();
if(xmlHttpRequest){
var url = "sendMessageController.php";
var data="con="+$("con").value+"&getter=<?php echo $username_chat;?>"+"&sender=<?php echo $loginuser;?>";
xmlHttpRequest.open("post",url,true);
xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttpRequest.onreadystatechange=function(){
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
if(xmlHttpRequest.responseText == "err"){
//把发的话显示到聊天框
$("return_con").value += "error\r\n";
}
}
}
};
xmlHttpRequest.send(data);
$("return_con").value += "你对<?php echo $username_chat;?>"+"说: "+$("con").value+" ["+getNowTime()+"]\r\n";
$("con").value="";
}
}
聊天室(<?php echo $loginuser;?>正在和<?php echo $username_chat;?>聊天)
一键复制
编辑
Web IDE
原始数据
按行查看
历史