我可以在$ 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.
答
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));
答
After 3 days of struggle and headache I finally got my answer own my own. For those who might come with same thinking about pagination as I did, if you want to do pagination for ajax call get or post, best way will be to change ajax_pagination library.
ajax_pagination -> create_links() -> getAJAXlink()
and edit its code as u want to.