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     }
  • 相关阅读:
    Supreme(ง •̀_•́)ง
    基于VS快速排序的单元测试
    POST GET
    Go对比其他语言新特性1(字符类型、类型转换、运算符、键盘输入、for、switch)
    四则运算问题
    软件工程第三次作业!
    Servlet
    结对编程1
    Kafka技术原理知识点总结
    KafkaStream简介
  • 原文地址:https://www.cnblogs.com/lovebing/p/6823455.html
Copyright © 2011-2022 走看看