我正在使用Code igniter(在codeigniter上新建),我想在$ .get上进行分页。
控制器代码在这里:
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));
}
现在关于创建html响应的js文件
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');
};
我希望它拥有o.links以获得$ .get。
答案 0 :(得分:0)
你忘了退回你的输出。在控制器方法string xmlContent =
string.Format("<CardNumber>{0}</CardNumber>" +
"<ExpMo>{1}</ExpMo>" +
"<ExpYr>{2}</ExpYr>" +
"<FirstName>{3}</FirstName>" +
"<LastName>{4}</LastName>",
CardNumber, ExpMo, ExpYr, FirstName, LastName);
中编辑最后一行:
l = ['a', '2', 'b', '1', 'c', '4']
d = {k:v for k,v in zip(l[::2], l[1::2])}
答案 1 :(得分:0)
ajax_pagination - &gt; create_links() - &gt; getAJAXlink()强>
并根据需要编辑其代码。