php - 如何用Ajax CI实现 关注好友 功能
PHPz
PHPz 2017-04-10 13:10:56
0
3
709

上面是HTML

$('#follow').click(function(){ if($(".follow").text() == "关注") { var form_data = { pid:, ajax:'1' }; $.ajax({ url:"", type:'POST', data:form_data, success:function(msg){ $('#follow').html(); } }); } else { var form_data = { pid:, ajax:'1' }; $.ajax({ url:"", type:'POST', data:form_data, success:function(msg){ $('#follow').html(msg); } }); } return false; })

上面是我写的jquery代码,功能实现了,但是为什么只有等手动刷新本页面才能看到结果呢?
下面的 CI控制器的写法,求指导。。

function addfollow(){ $pid = $this->input->post('pid'); if($this->input->post('ajax')){ } }
PHPz
PHPz

学习是最好的投资!

reply all (3)
数据分析师

php - How to use Ajax CI to implement the function of following friends - PHP Chinese website Q&A - php - How to use Ajax CI to implement the function of following friends - PHP Chinese website Q&A

Take a look around and learn.

    大家讲道理

    好吧,问题我自己解决了 要感谢@joyqi 的提示
    主要是是操作数据的时候没有返回值, $ajax重写一定要这样写

    success:function(msg){ $('#follow').html(msg); }

    返回的#follow 要单独写一个文件

    CI 控制器要这样写:

    function addfollow(){ $pid = $this->input->post('pid'); if($this->input->post('ajax')){ $data['pid'] = $pid; $this->load->view('follow', $data); } }
      黄舟

      你ajax返回的应该是当前返回数吧,你看看你follow的js代码里

      success:function(msg){ $('#follow').html(); }

      这里应该是$('#follow').html(msg);

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!