zoukankan      html  css  js  c++  java
  • 投票ajax请求代码(点赞代码)

     1 function vote(url, arr) {
     2     jq.ajax({
     3         cache: false,
     4         async: false,
     5         url: url,
     6         type: 'post',
     7         data: {info_arr: arr},
     8         dataType: 'json',
     9         error: function (a) {
    10         },
    11         success: function (json) {
    12             if (json.status == 1) {
    13                 alert(json.info);
    14                 //直接刷新页面,不用ajax
    15                 location.reload();
    16             } else {
    17                 alert(json.info);
    18                 return false;
    19             }
    20         }
    21     });
    22 }

    后台处理代码:

     1     public function pzan(){
     2         $ip = get_client_ip(); //获取用户IP   
     3         $id = $_POST['id'];   
     4         if(!isset($id) || empty($id)) exit; 
     5         $map['pid'] = $id;
     6         $map['ip'] = $ip;
     7         $zan = M('zan_ip');
     8         $count = $zan->where($map)->count();
     9         if($count){
    10             //已经存在记录,赞过了。
    11             $info['status'] = 0;
    12             $info['msg'] = '已经赞过咯!';
    13             $this->ajaxReturn($info);        
    14         }else{
    15             //第一次赞
    16             $map1['id'] = $id;
    17             $p = M('project');//查看是否已经赞过这个文章
    18             $p->where($map1)->setInc('points',1);
    19             $data['pid'] = $id;
    20             $data['ip'] = $ip;
    21             $zan->create($data);
    22             $zaninfo = $zan->add();
    23             if ($zaninfo) {
    24                 $info['status'] = 1;
    25                 $info['msg'] = '点赞成功!!';
    26                 $this->ajaxReturn($info);  
    27             }
    28 
    29         }
    30 
    31     }
  • 相关阅读:
    webim-界面细节调整
    使用PHP得到所有的HTTP请求头_还有应答头
    Bootstrap学习的点点滴滴
    asterisk中eyebeam与移动的IMS帐号对接
    总结Ajax跨域调用问题
    Spring【基础】-注解-转载
    Spring-【高阶】注解-转载
    让你的IDEA倍爽
    IDEA的git密码修改
    Idea设置签名
  • 原文地址:https://www.cnblogs.com/lovebing/p/6823455.html
Copyright © 2011-2022 走看看