简单很实用的聊天室(不看会后悔的哦!~~~)

3 篇文章 0 订阅
3 篇文章 0 订阅
<?php


include 'checkUser.php';


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>无标题文档</title>


<style>
#chatContent{
width:500px;
height:300px;
background-color:#FFFF99;
text-align:left;
overflow:scroll;
}
table{
margin:auto auto;
background-color:#999999;
}
td,tr{
border:#CC0000 1px solid;
text-align:center;
}
#send_btn{
width:65px;
height:65px;
color:#0000FF;
}
#sp{font-size:14px;}
</style>
<script language="javascript" type="text/javascript" src="include/ajaxUtil.js"></script>
<script language="javascript" type="text/javascript" src="include/fckeditorUtil.js"></script>




<script language="javascript" type="text/javascript">
//发送用户说的内容
function sendMsg(){
var url="sendMsg.php";
var content=getEditorHtmlContents("content",true);


var params="nr="+encodeURI(content)+"&lis="+encodeURI($$('onlineuser').value)+"&name="+"<?php echo $_SESSION["username"];?>";
get(url,params,processSendMsg);


}
function processSendMsg(xhr){

if(xhr.responseText){
SetEditorContents("content","");
}else{
alert("发送失败!");
}
}
var maxid=0;
//获取内容,并且显示出来
function getContent(){
var url="getContent.php";
var params="maxid="+maxid;
get(url,params,processGetContent);
}
function processGetContent(xhr){
//把json格式的字符串转化为对象
var obj=eval("("+xhr.responseText+")");
//取出所有的聊天信息
var rows=obj.Msgs;
//取出所用用户信息
var users=obj.Users;
//--------------------显示在线用户---------------------
//获取在线用户的select的对象
var sel=$$("onlineuser");
//清空在线上次查询在线信息
sel.options.length=0;
for(var m=0;m<users.length;m++){
//产生一个选项
var op=new Option(users[m].username+"@"+users[m].theip,users[m].id);
//把选项添加到在线用户列表中
sel.options.add(op);
}



//-----------------------显示聊天信息------------
var conStr=$$("chatContent").innerHTML;
//var conStr="";
for(var i=0;i<rows.length;i++){

conStr+="&nbsp;"+rows[i].speaker+"["+rows[i].theip+"]&nbsp;在&nbsp;"+rows[i].create_time+"&nbsp;说:</span><br>&nbsp;&nbsp;"+rows[i].content+"<br>";
maxid=parseInt(rows[i].id);
}
//把最大的id值赋值给maxid
//maxid=rows[i].id;
//将内容显示到div中
$$("chatContent").innerHTML=conStr;
//$$("chatContent").scrollTop=$$("chatContent").scrollHeight;
}
setInterval("getContent()",2000);
</script>


</head>


<body>


<table width="300" border="1">
<caption>ajax+json+php+js+dom+mysql实现聊天室<br></caption>
  <tr>
    <td>欢迎 <?php echo $_SESSION['username']; ?>,进入聊天室</td>
    <td>在线用户列表</td>
  </tr>
  <tr>
    <td><div id="chatContent"></div></td>
    <td><select id="onlineuser" size="20" style="width:150px;">
<option>所有人</option>
</select>
</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><?php 
//引用FCKeditor.php这个文件,基本的类和数据结构都在这里
include ("fckeditor/fckeditor.php");
//创建FCKeditor对象的实例。myFCKeditor即提交后,接收数据页面 _POST['myFCKeditor']使用
$FCKeditor = new FCKeditor("content");
//FCKeditor所在的位置,这里它的位置就是'FCKeditor' 文件夹
$FCKeditor -> BasePath='./fckeditor/';
//工具按钮设置
$FCKeditor -> ToolbarSet="ChatEditor";
//设置它的宽度
$FCKeditor -> Width='500px';
//设置它的高度
$FCKeditor -> Height='120px';


$FCKeditor ->InstanceName ="content";
//生成
$FCKeditor -> Create();
?></td>
    <td><input type="button" value="发送" id="send_btn" οnclick="sendMsg()" /></td>
  </tr>
</table>


</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值