douhuireng4407 2015-07-30 17:40
浏览 193
已采纳

我可以在$ this-> pagination-> create_links()中调用$ .get;

I am working on Code igniter (new at codeigniter) and I want to do pagination on $.get.

Contoller Code is here:

public function get_todo($id=null)
{
     $this->_required_login();
     if($id!=null)
     {
         $result=$this->todo_model->get([
             'todo_id'=>$id,
             'user_id'=>$this->session->userdata('user_id')
         ]);

     }
     else
     {
         $config = array();
    $config["base_url"] = base_url() . "dashboard/load_todo";   // I want here is $.get instead of a link
    //I have js files in which $.get is.
    $total= $this->todo_model->get_rows($this->session->userdata('user_id')); //Total rows
    $config["total_rows"] = $total;
    $config["per_page"] = 3; // Per Page required
    // I have no idea what it is.
    $config["uri_segment"] = 3;

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    // no idea thing ends here

    //getting results and working fine
    $data["results"] = $this->todo_model->
        fetch_data($config["per_page"], $page);
    // Real pain in the neck
    $data["links"] = $this->pagination->create_links();

     }
     $this->output->set_output(json_encode($data));


}

Now about js file which is creating html response

    var load_todo = function() {
    $.get('api/get_todo',function(o){
        //api/get_todo is controller
       var output='';

       for (var i=0;i<o.results.length;i++)
       {
           output+=Template.todo(o.results[i]);  // Pagination result
       }
       output+='<p>'+o.links+'</p>'; // Pagination links
       //console.log(output);
        $("#list_todo").html(output);
    },'json');
};

What I want it to have o.links to have $.get.

  • 写回答

2条回答 默认 最新

  • doumingchen3628 2015-07-30 18:56
    关注

    you forgot to return your output. In your controller method get_todo() edit the last line to this:

     return $this->output
                 ->set_content_type('application/json')
                 ->set_output(json_encode($data));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog