我想通过过滤器将分页页面创建为无限滚动。我正在使用codeigniter。分页工作正常。将复选框值(对于过滤器)传递给控制器时,它显示为null。单击复选框时,它不是警报数据。我好几天都在挣扎。如果你能帮助我,我将非常感激。谢谢。
的Ajax
<script type="text/javascript">
$(document).ready(function() {
var total_record = 0;
var total_groups = <?php echo $total_data; ?>;
//brand is the checkbox value
var brand=check_box_values('brand');
$('#results').load("<?php echo base_url() ?>content/load_more",
{'group_no':total_record,'brand':brand}, function() {total_record++;});
$(window).scroll(function() {
if($(window).scrollTop()+$(window).height() >= $('#fooerdivid').offset().top)
{
if(total_record <= total_groups)
{
loading = true;
$('.loader_image').show();
$.post('<?php echo site_url() ?>content/load_more',{'group_no': total_record,'brand':brand},
function(data){
if (data != "") {
$("#results").append(data);
$('.loader_image').hide();
total_record++;
}
});
}
}
});
//For passing checkbox values
function check_box_values(check_box_class){
var values = new Array();
$("."+check_box_class+":checked").each(function() {
values.push($(this).val());
});
return values;
}
});
</script>
public function load_more()
{
$group_no = $this->input->post('group_no');
$brand = $this->input->post('brand');
$content_per_page = 5;
$start = ceil($group_no * $content_per_page);
$all_content = $this->content_model->get_all_content($start,$content_per_page,$brand);
if(isset($all_content) && is_array($all_content) && count($all_content)) :
foreach ($all_content as $key => $content) :
echo '<li>'.$content->title.'</li>';
echo '<p>'.$content->description.'</p>';
endforeach;
endif;
}
模型
public function get_all_content($start,$content_per_page,$brand)
{
$sql = "SELECT * FROM content_information LIMIT $start,$content_per_page";
if(isset($brand))// your condition here
{
$this->db->where_in('brand', $brand);
}
$result = $this->db->query($sql)->result();
return $result;
}
答案 0 :(得分:2)
试试这段代码。在document.ready函数上调用函数来加载第一个数据。在复选框的单击事件中,您需要再次调用该函数以获取下一个数据。另外在window.scroll上,您必须加载数据。
$(document).ready(function() {
load_content();
function load_content(){
var total_record = 0;
var total_groups = <?php echo $total_data; ?>;
//brand is the checkbox value
var brand=check_box_values('brand');
$('#results').load("<?php echo base_url() ?>content/load_more",
{'group_no':total_record,'brand':brand}, function() {total_record++;});
}
//For passing checkbox values
function check_box_values(check_box_class){
var values = new Array();
$("."+check_box_class).each(function() {
if($(this).is(':checked')){
values.push($(this).val());
}
});
return values;
}
$(".brand").click(function(){
load_content();
});
$(window).scroll(function() {
if($(window).scrollTop()+$(window).height() >= $('#fooerdivid').offset().top)
{
var total_record = 0;
var total_groups = <?php echo $total_data; ?>;
//brand is the checkbox value
var brand=check_box_values('brand');
if(total_record <= total_groups)
{
loading = true;
$('.loader_image').show();
$.post('<?php echo site_url() ?>content/load_more',{'group_no': total_record,'brand':brand},
function(data){
if (data != "") {
$("#results").append(data);
$('.loader_image').hide();
total_record++;
}
});
}
}
});
});
请忽略语法错误,因为我没有测试过代码,但你会从中得到一个想法。