時間: 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){ //獲取數(shù)據(jù)成功 //此處對頁面已經(jīng)顯示的{content:likes}+1,注意JS中需要轉(zhuǎn)換為數(shù)字,才能進行+1,否則會是字符串拼接。 alert(response.data); }else{ //返回錯誤數(shù)據(jù) alert(response.data); } }, error:function(xhr,status,error){ //返回數(shù)據(jù)異常 alert('返回數(shù)據(jù)異常!'); } }); }); |
// 點贊 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小時內(nèi)只能點贊一次哦!'); } } else { json(0, '點贊失敗'); } } |
下一篇: PbootCms模板中怎么寫PHP代碼