最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php+ajax实现无刷新的新闻留言系统(附源码)
时间:2022-06-24 15:30:34 编辑:袖梨 来源:一聚教程网
最简明易懂的一个ajax无刷新留言系统了,源码中省略了接受数据验证的过程。读者可根据自己的需求进行扩展。
核心源码:
1.配置文件:config.php
| 代码如下 | 复制代码 |
|
$cfg_dbhost = "localhost"; $cfg_dbuser = "root"; $cfg_dbpwd = "root"; $cfg_dbname = "ajaxdemo1"; $cfg_dbprefix = "";
mysql_select_db($cfg_dbname); mysql_query("set names utf8"); ?> |
|
2.处理请求:deal.php
| 代码如下 | 复制代码 |
|
header("Content-type:text/html;charset=utf-8"); include "config.php"; //post接收数据,只是演示效果,这里就省去验证了 $name = $_POST['name']; $content = $_POST['content'];
$res = mysql_query($sql,$link); if($res){ echo '{"name": "'.$name.'","content": "'.$content.'","status": "1"}'; } ?> |
|
3.首页代码:index.php
| 代码如下 | 复制代码 |
|
body{color:#555;font-size:14px;padding:0;margin:0;} #form { background:#dedede; padding:10px 20px; width:300px;} #show{ background:#f6f6f6;padding:10px 20px; width:300px;} #show p{ margin:6px; font-size:13px; line-height:22px; border-bottom:1px dashed #cdcdcd;} $(function(){ $("#sub").click(function(){ //只是说明原理,然后这里省去了验证文本框内容的步骤,直接发送ajax请求 $.post("deal.php",{name : $("#name").val(), content : $("#content").val()}, function(data){ if(data.status){ var str = " "+data.name+" 发表了:"+data.content+" ";$("#show").prepend(str); //在前面追加 }else{ alert("评论失败"); } }, 'json'); }); });
include "config.php"; $sql = "select * from test;"; $res = mysql_query($sql,$link); while($row=mysql_fetch_array($res)){ echo " ".$row['name']." 发表了:".$row['content']." ";} ?> |
|
数据库文件
| 代码如下 | 复制代码 |
|
|
|
源码下载地址:php+ajax实现无刷新的新闻留言系统下载
相关文章
- QQ经典版下载安装最新版-QQ经典版轻量版app官方正式版下载 12-17
- 豆包网页版官方入口-豆包网页版一键直达官网 12-17
- 抖音网页版官方入口-在线畅玩douyin.com 12-17
- 土豪漫画官方下载入口-安卓/iOS一键安装APP 12-17
- QQ经典版最新版本下载安装-QQ经典版app官方正版下载地址 12-17
- 漫蛙官网入口网页直达-漫蛙官网入口官方认证链接 12-17
