jquery和php评论,Ajax应用:jQueryPHPMySQL发表评论

在本文中,我将带你一起使用PHP,MySQL和jQuery创建一个快速高效的发表评论的功能。您可以将此功能应用在留言、评论等领域。

097fc3fc74b104802d9938b325e3491c.png

下载资源

下载积分:

70

积分

HTML

首先我们放置一个评论表单和显示评论列表#comments

发表评论

昵称:

评论内容:

jQuery

接着调用评论列表,并且通过Ajax发布评论: $(function() {

var comments = $("#comments");

$.getJSON("ajax.php",

function(json) {

$.each(json,

function(index, array) {

var txt = "

" + array["user"] + ":" + array["comment"] + "" + array["addtime"] + "

";

comments.append(txt);

});

});

$("#add").click(function() {

var user = $("#user").val();

var txt = $("#txt").val();

$.ajax({

type: "POST",

url: "comment.php",

data: "user=" + user + "&txt=" + txt,

success: function(msg) {

if (msg == 1) {

var str = "

" + user + ":" + txt + "刚刚

";

comments.append(str);

$("#message").show().html("发表成功!").fadeOut(1000);

$("#txt").attr("value", "");

} else {

$("#message").show().html(msg).fadeOut(1000);

}

}

});

});

});

Mysql

最后附上表comments结构: CREATE TABLE `comments` (

`id` int(11) NOT NULL auto_increment,

`user` varchar(30) NOT NULL,

`comment` varchar(200) NOT NULL,

`addtime` datetime NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM;

赶紧去试试吧,点击评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值