时间: 2024-03-11 20:23:43 人气: -
$(document).ready(function (e) {
var url='/api.php/do/likes/id/'+{content:id};
$.ajax({
type: 'POST',
url: url,
dataType: 'json',
data: {
appid: '{pboot:appid}',
timestamp: '{pboot:timestamp}',
signature: '{pboot:signature}'
},
success: function (response, status) {
if(response.code){
//获取数据成功
//此处对页面已经显示的{content:likes}+1,注意JS中需要转换为数字,才能进行+1,否则会是字符串拼接。
alert(response.data);
}else{
//返回错误数据
alert(response.data);
}
},
error:function(xhr,status,error){
//返回数据异常
alert('返回数据异常!');
}
});
});
|
// 点赞
public function likes()
{
if (! ! $id = request('id', 'int')) {
if(! cookie('likes_' . $id)){
$this->model->addLikes($id);
cookie('likes_' . $id, true, 86400, null, null, null, null);
json(1, '点赞成功');
}else{
json(0, '24小时内只能点赞一次哦!');
}
} else {
json(0, '点赞失败');
}
}
|
上一篇: pbootcms模板如何修改后台版权
下一篇: PbootCms模板中怎么写PHP代码