我正在使用CodeIgniter的分页API.当我点击特定页面时,我发现了一些问题:它显示了URL中的控制器和页面.我不想在URL中显示所有细节.
我有大量的搜索条件.
例如 http:// localhost/myapp/search/pages/2&fromAge = 25 ......等等
有没有办法用POST方法而不是GET来处理它?
请帮忙.
小智 8
如果你想使用POST的分页,有一种简单的方法可以使用标准的CI分页和没有Ajax.只需单击分页链接,即可执行POST而不是GET.为此,您需要表单中的隐藏字段(在我的示例中命名为页面),其中包含页码,您需要在提交之前使用链接设置表单的action属性(分页类需要计算当前页面).在下面找到jquery中的示例代码:
// bind onclick event to the pagination links
$('.pagination a').click(function () {
var link = $(this).get(0).href; // get the link from the DOM object
var form = $('#form1'); // get the form you want to submit
var segments = link.split('/');
// assume the page number is the fifth parameter of the link
$('#page').val(segments[4]); // set a hidden field with the page number
form.attr('action', link); // set the action attribute of the form
form.submit(); // submit the form
return false; // avoid the default behaviour of the link
});
Run Code Online (Sandbox Code Playgroud)
在服务器端,您从名为page的POST字段读取页码,以使用分页执行db查询,并使用常用函数构建分页链接