Thinkphp + ajax partial refresh thumb ups-PHP source code

Source: Internet
Author: User
Thinkphp + ajax partial refresh thumb ups thinkphp thumb ups

public function zan(){        $data['id']=isset($_POST['id'])?intval(trim($_POST['id'])):0;        $obj = M("Article");         if(!isset($_COOKIE[$_POST['id']+10000])&&$obj->where($data)->setInc('zan')){            $cookiename = $_POST['id']+10000;            setcookie($cookiename,40,time()+60,'/');              $data['info'] = "ok";            $data['status'] = 1;            $this->ajaxReturn($data);                         exit();        }else{            $data['info'] = "fail";            $data['status'] = 0;            $this->ajaxReturn($data);            exit();        }             }

Js

$ (". Z "). on ('click', function () {var Oa = $ (this); var id = Oa. attr ('id'); // Obtain the id attribute var vl = Oa. find ("span "). text (); vl = parseInt (vl) + 1; $. post ('_ CONTROLLER _/zan', {id: id}, function (data) {if (data. status = 1) {alert ('thank you for your support! '); // Simulate asynchronous data and add 1 Oa. find ("span "). text (vl); // add 1} else {alert to the page element ('you have already liked it. do not repeat it! ') ;}}, 'Json ');})

Page

"Href =" javascript: void (0); "> like <{$ list. zan}>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.