天天看点

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

<?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>????棰???妗?lt;/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;??amp;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;

//灏???瀹规?剧ず??iv涓?

$$("chatContent").innerHTML=conStr;

//$$("chatContent").scrollTop=$$("chatContent").scrollHeight;

}

setInterval("getContent()",2000);

</script>

</head>

<body>

<table width="300" >

<caption>ajax+json+php+js+dom+mysql瀹??拌??澶╁??lt;br></caption>

? <tr>

? ? <td>娆㈣? <?php echo $_SESSION['username']; ?>锛?杩??ヨ??澶╁??lt;/td>

? ? <td>?ㄧ嚎?ㄦ?峰??琛?lt;/td>

? </tr>

? <tr>

? ? <td><div id="chatContent"></div></td>

? ? <td><select id="onlineuser" size="20" style="width:150px;">

<option>????浜?lt;/option>

</select>

</td>

? </tr>

? <tr>

? ? <td>&nbsp;</td>

? ? <td>&nbsp;</td>

? </tr>

? <tr>

? ? <td><?php?

//寮???CKeditor.php杩?涓???浠讹??烘????绫诲???版??缁????藉?ㄨ???

include ("fckeditor/fckeditor.php");

//??寤?CKeditor瀵硅薄??瀹?渚???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>