簡體   English   中英

CakePHP通過ajax分頁加載更多結果

[英]CakePHP load more results with ajax pagination

我一直在追隨一場狂歡,但是我被困在這一部分:

視圖:

<?php if (!$isAjax):?>
<script type="text/javascript">
var lastX = 0;
var currentX = 0;
var page = 1;
$(window).scroll(function () {
currentX = $(window).scrollTop();
if (currentX - lastX > 200 * page) {
lastX = currentX;
page++;
$.get('<?php echo $this->base."/products/index/page:"; ?>' + page, function(data) {
$('#prod-list').append(data);
});
}
});
</script>
<?php endif;?>

控制器:

var $components = array('RequestHandler');

public function index($page) {
$limit = 8; 
$data = $this->Products->list_products($page, $limit);
$this->set('products',$data); 
$this->set('isAjax', $this->RequestHandler->isAjax());}

然后模型檢索一些數據。 問題在於,在視圖中,完整的html頁面被追加到prod-list而不是新的結果。 我該如何“修復”該問題?

我讀過某個地方的文章,可能需要一個新視圖來獲取結果並通過Ajax獲取它。 這讓我感到困惑。

編輯:尊重AD7six注意,我已經從$ this-> layout = false更改了一段代碼; 到$ this-> layout ='ajax';。

您需要使用ajax布局。

if ($this->request->is('ajax')) {
        $this->disableCache(); 
        $this->layout = 'ajax';
        $this->render('your_view_file');
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM