首页 > 编程 > PHP > 正文

PHP之AJAX、POST传值【顶、踩】

2019-11-14 11:17:48
字体:
来源:转载
供稿:网友
顶一下为事例:top_reply表结构:id标识,rid关联ID,uid用户
<script>function toPReply(arid,rid){$.Ajax({type: "POST",url: "{YICMS::U('Index/topreply')}",dataType:'json',//从php返回的值以 JSON方式data: {arid:arid,rid:rid},success: function(msg){alert(msg.info);$('#toprp-'+rid).html(msg.topnum);}});}</script>
<?php public function topreply(){$data['uid'] = $_POST['arid'];$data['rid'] = $_POST['rid'];$map['uid'] = $data['uid'];$map['rid'] = $data['rid'];if(M('TopReply')->where($map)->select()){$topnum = M('TopReply')->where('rid='.$map['rid'])->count();$res['topnum'] = $topnum;$res['info'] = '您已经点过赞啦';echo json_encode($res);}else{M('TopReply')->add($data);$topnum = M('TopReply')->where('rid='.$map['rid'])->count();$res['topnum'] = $topnum;$res['info'] = '点赞成功';echo json_encode($res);}}?> 
<a href="javascript:topreply( {$value['arid']} , {$value['id']} )">顶<div id="toprp-{$value['id']}">{$topnum}</div>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表