时间:2021-07-01 10:21:17 帮助过:17人阅读
*******chatRoom.php******
//接受open传递的用户名
$username=$_GET['username'];
$username=trim($username);
session_start();
$loginuser=$_SESSION['loginuser'];
?>网页聊天室(正在和聊天)
*********getMessageController.php********
require_once 'MessageService.class.php';
header("content-type:text/xml;charset=utf-8");
header("Cache-Control:no-cache"):
$getter=$_POST['getter'];
$sender=$_POST['sender'];
$messageService=new MessageService();
$messageList=$messageService->getMessage($getter,$sender);
echo $messageList;
?>
*********MessageService.class.php********
require_once 'SqlHelper.class.php';
class MessageService{
function addMessage($sender,$getter,$con){
$sql="insert into messages (sender,getter,content,sendtime) values ('$sender','$getter','$con',now())";
$sqlHelper=new SqlHelper();
return $sqlHelper->execute_dml($sql);
}
function getMessage($getter,$sender){
$sql="select * from messages where getter='$getter' and sender='$sender' and isGet=0";
$sqlHelper=new SqlHelper();
$array=$sqlHelper->execute_dql2($sql);
$messageInfo=""; ";
for($i=0;$i$row=$array[$i];
$messageInfo.="{$row['id']} {$row['sender']} {$row['getter']} {$row['content']} {$row['sendtime']} ";
}
$messageInfo.="
$sqlHelper->close_connect();
return $messageInfo;
}
}
?>
....
if(myXmlHttpRequest.status==200){
var mesRes=myXmlHttpRequest.responseXML;
if(mesRes.xml == '') { //如果不是 xml 对象
alert(myXmlHttpRequest.responseText);//看一下究竟返回了什么
return;
}
....