<?php
// 配置信息:
// 1,数据库连接的具体信息
// 2,我们要存储的消息的数目
// 3,用户进到聊天室的时候消息显示的数目
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "chat";
$store_num = 10;
$display_num = 10;
// 错误报告
error_reporting(E_ALL);
// 头部信息
header("Content-type: text/xml");
header("Cache-Control: no-cache");
//连接mysql
$dbconn = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$dbconn);
//为容易操作请求数据,我们为请求中的每个参数设置一个变量,每个变量将把请求中的参数值作为其自己的值
//foreach语句遍历所有的POST数据,并且为每个参数创建一个变量,并且给它赋值
foreach($_POST as $key => $value){
$$key = mysql_real_escape_string($value, $dbconn);
}
//屏敝任何错误提示,判断action是否等于 postmsg
if(@$action == "postmsg"){
//插入数据
mysql_query("INSERT INTO messages (`user`,`msg`,`time`)
VALUES ('$name','$message',".time().")",$dbconn);
//删除数据(因为我们默认值存储10条数据)
mysql_query("DELETE FROM messages WHERE id <= ".
(mysql_insert_id($dbconn)-$store_num),$dbconn);
}
//查询数据
$messages = mysql_query("SELECT user,msg
FROM messages
WHERE time>$time
ORDER BY id ASC
LIMIT $display_num",$dbconn);
//是否有新记录
if(mysql_num_rows($messages) == 0) $status_code = 2;
else $status_code = 1;
//返回xml数据结构
echo "<?xml version=\"1.0\"?>\n";
echo "<response>\n";
echo "\t<status>$status_code</status>\n";
echo "\t<time>".time()."</time>\n";
if($status_code == 1){ //如果有记录
while($message = mysql_fetch_array($messages)){
$message['msg'] = htmlspecialchars(stripslashes($message['msg']));
echo "\t<message>\n";
echo "\t\t<author>$message[user]</author>\n";
echo "\t\t<text>$message[msg]</text>\n";
echo "\t</message>\n";
}
}
echo "</response>";
?>
没有合适的资源?快使用搜索试试~ 我知道了~
jquery最全面的ajax例子 ajax post get load 应有尽有
共125个文件
html:79个
js:10个
php:10个
5星 · 超过95%的资源 需积分: 33 242 下载量 32 浏览量
2009-07-29
10:51:41
上传
评论 2
收藏 205KB RAR 举报
温馨提示
load()方法 、 $.get()和$.post()方法 、 $.getScript()和$.getJson() 、 $.ajax()方法 、 序列化元素 、 jQuery中的Ajax全局事件 这些都有详尽的例子,一看代码,你就能明白jquery里实现ajax是怎么回事了,简单明了。
资源推荐
资源详情
资源评论
收起资源包目录
jquery最全面的ajax例子 ajax post get load 应有尽有 (125个子文件)
post2.asp 834B
get2.asp 763B
post1.asp 287B
post3.asp 259B
get1.asp 238B
get1.asp 238B
get1.asp 238B
get3.asp 188B
test.asp 39B
demo1.html 2KB
demo1.html 2KB
demo1.html 2KB
demo1.html 2KB
get2.html 2KB
post2.html 2KB
get3.html 2KB
get2.html 2KB
post3.html 2KB
get3.html 2KB
get2.html 2KB
post2.html 2KB
post2.html 2KB
demo1.html 2KB
demo1.html 2KB
get3.html 2KB
demo1.html 2KB
post3.html 1KB
post3.html 1KB
demo2.html 1KB
demo2.html 1KB
demo2.html 1KB
demo3.html 1KB
get1.html 1KB
demo2.html 1KB
get1.html 1KB
post1.html 1KB
demo2.html 1KB
demo2.html 1KB
demo3.html 1KB
post1.html 1KB
post1.html 1KB
get1.html 1KB
demo3.html 1KB
demo3.html 1KB
demo3.html 1KB
demo3.html 1KB
demo1.html 1KB
demo3.html 1KB
get4.html 1KB
demo3.html 1KB
demo3.html 1KB
demo1.html 1KB
demo1.html 1KB
firebug.html 1KB
post4.html 1KB
post4.html 1KB
demo3.html 1KB
get4.html 1KB
demo2.html 1KB
post4.html 1KB
demo3.html 1KB
demo3.html 1KB
get4.html 1KB
demo2.html 1KB
demo2.html 1KB
demo4.html 1KB
demo4.html 1KB
demo4.html 1KB
demo1.html 1KB
demo1.html 1KB
demo1.html 1KB
firebug.html 999B
firebug.html 999B
demo1.html 994B
demo2.html 986B
demo1.html 980B
demo1.html 974B
demo1.html 974B
demo2.html 971B
demo2.html 971B
demo1.html 965B
demo1.html 965B
demo5.html 581B
demo5.html 581B
demo5.html 581B
test.html 541B
test.html 541B
test.html 540B
jquery-1.3.1.js 115KB
jquery-1.3.1.js 115KB
jquery-1.3.1.js 115KB
jquery-1.3.1.js 115KB
test.js 434B
test.js 434B
test.js 434B
test.js 434B
test.js 434B
test.js 434B
test.json 182B
test.json 182B
共 125 条
- 1
- 2
陆仁
- 粉丝: 6
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页