我想将我的page_num的值从 jQuery 获取到我的控制器,但我无法获得更新的值,我只获得了第一次传递的值。当我向下滚动时,我的滚动连续显示结果,它不会停止,也没有显示所有结果,它只显示前 6 个,然后连续重复。
我正在使用 jQuery ScrollPagination,但无法解决问题 - 请帮助我。
这是我的看法:
<div id="main" style="width:760px">
<div id='friend_display'>
<?php if($list->num_rows() > 0 ){
foreach($list->result() as $show){ ?>
<!-- image box -->
<div class="image-box" style="margin-left:30px" id='image-holder' >
<div class="photo-cover">
<img width="160px" height="117px" src="<?=base_url()?>uploads/user_images/friends/<?php echo $show->user_image;?>" alt="" />
</div>
<p class="photo-name"><b><?php echo $show->user_name;?></b></p>
<!-- end photo name -->
</div>
<?php } } else { echo '<div align="center" style="color:#FF0000; font-size:17px; font-weight:bold">You have no Friends yet</div>';}?>
<!-- end image-box -->
<div class="cl"> </div>
</div>
<!-- end main -->
</div>
<div class="loading1" id="loading1">Wait a moment... it's loading!</div>
<div class="loading1" id="nomoreresults">Sorry, no more results....!</div>
这是我的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Friends extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('friends_model');
}
function find_friends($offset=0)
{
$friend['list'] = $this->friends_model->find($offset);
$this->load->view('friends_find_view',$friend);
}
function display_friends()
{
$offset = $this->input->post('page_num');
$find = $this->friends_model->find($offset);
if($find->num_rows() > 0 )
{
foreach($find->result() as $show)
{ ?>
<div class="image-box" style="margin-left:30px" id='image-holder' >
<div class="photo-cover">
<img width="160px" height="117px" src="<?=base_url()?>uploads/user_images/friends/<?php echo $show->user_image;?>" alt="" />
</div>
<p class="photo-name"><b><?php echo $show->user_name;?></b></p>
<!-- end photo name -->
</div>
<?php } } else { exit; }?>
<!-- end image-box -->
<div class="cl"> </div>
<?php
}
}
如果我回显 $offset则每次 bt 在脚本中显示 6 page_num值正在正确更改。这是主要问题。
这是型号代码
function find($offset)
{
$this->db->select('*');
$this->db->from('users');
$this->db->limit(6,$offset);
$result = $this->db->get();
return $result;
}
最后这是我的脚本
<script type="text/javascript">
var page_num = 1;
$(function(){
$('#friend_display').scrollPagination({
'contentPage': '<?=base_url()?>friends/display_friends', // the url you are fetching the results
'contentData': {page_num:$('.image-box').size()}, // these are the variables you can pass to the request, for example: children().size() to know which page you are
'scrollTarget': $(window), // who gonna scroll? in this example, the full window
'heightOffset': 10, // it gonna request when scroll is 10 pixels before the page ends
'beforeLoad': function(){ // before load function, you can display a preloader div
$('#loading1').fadeIn();
},
'afterLoad': function(elementsLoaded){ // after loading content, you can use this function to animate your new elements
$('#loading1').fadeOut();
$(elementsLoaded).fadeInWithDelay();
page_num:$('.image-box').size();
}
});
// code for fade in element by element
$.fn.fadeInWithDelay = function(){
var delay = 0;
return this.each(function(){
$(this).delay(delay).animate({opacity:1}, 200);
delay += 100;
});
};
});
</script>
我第二次问这个问题,希望这次我能得到我的解决方案,谢谢。您还可以在此处查看完整代码滚动分页代码