本篇文章主要讲解php+ajax搭建简易聊天室实践,文中有关php,ajax的内容,有需要的小伙伴参考下。
index.html:
新建网页
在线名单:(5人)
- 帅哥:恶魔
- 靓妹:甜甜
- 帅哥:诸葛
- 帅哥:成就梦想
- 靓妹:郁金香
有什么意见和建议欢迎大家踊跃提出
PHP爱好者聊天室公告:欢迎恶魔来到聊天室(22:05:35)
恶魔 对 大家 微笑 说:对啊(22:05:35)
恶魔 对 大家 微笑 说:对啊(22:05:35)
恶魔 对 大家 微笑 说:好久不见了啊(22:05:35)
PHP爱好者聊天室公告:欢迎天使来到聊天室(22:05:35)
天使 对 大家 微笑 说:你来了啊(22:05:35)
立即学习“PHP免费学习笔记(深入)”;
data.php(后端,从数据库获取所有聊天信息):
".$maxID;
$qry = mysql_query($sql);
$info = array();
while($rst = mysql_fetch_assoc($qry)){
$info[] = $rst;
}
//把数据组织为二维数组
//把最新的聊天信息通过json格式提供出来
echo json_encode($info);send.php(后端,将发送的聊天记录存入数据库):
talk.css(引入的外部CSS文件):
* {margin:0;padding:0;border:0;} #main {width:900px; height:500px; background:pink; margin:auto; margin-top:10px;} #left {width:200px; height:500px;background:#F5DEB3; float:left;} #right {width:700px; height:500px; background:rgb(206,263,49); float:left;} #content {height:379px; padding-top:1px;} #send {height:120px; background:rgb(51,175,234);} #control {position:relative; left:75px; top:18px;} select,textarea {border:1px solid gray;} #msg {width:410px;height:52px; margin-top:5px;} #content-title{color:green;font-size:14px;width:245px;margin:10px auto;} hr {border:1px solid gray; width:600px; margin:auto;} #show_msg {width:600px; margin-left:47px;margin-top:10px;font-size:14px;font-weight:bold; height:327px; overflow:auto; } #left h2 {color:#8B4513;font-size:14px;position:relative; left:36px;top:24px; width:150px; } #left #user { position:relative; top:46px;left:48px; } ul {font-size:12px; list-style:none; width:110px; } #anniu {margin-top:280px; margin-left:50px; } #anniu input {margin-top:3px; width:98px;height:30px; background:#CD853F; color:white; border:2px solid white;}相关推荐:











