您好,我在互联网上找到了这个示例,如果它可以帮助您。
here
阿贾克斯:
$('body').delegate('.ajax-pagination a', 'click', function() {
$this = $(this);
$this.parents('div.ajax-response').filter(':first').block();
pageUrl = $this.attr('href');
$.get(pageUrl, function(data) {
$this.parents('div.ajax-response').filter(':first').html(data);
});
return false;
});
那么你必须在包含的分页元素的父 div 中添加类“ajax-pagination”。我的意思是
<div class="ajax-pagination">
<?php echo $this->element('paging_links'); ?>
</div>
我的 pagining_links.ctp 有以下代码:
<?php
$this->Paginator->options(array(
'url' => array_merge(array(
'controller' => $this->request->params['controller'],
'action' => $this->request->params['action'],
) , $this->request->params['pass'], $this->request->params['named'])
));
echo $this->Paginator->prev('« ' . __lang('Prev') , array(
'class' => 'prev',
'escape' => false
) , null, array(
'tag' => 'span',
'escape' => false,
'class' => 'prev'
)), "n";
echo $this->Paginator->numbers(array(
'modulus' => 2,
'first' => 3,
'last' => 3,
'ellipsis' => '<span class="ellipsis">….</span>',
'separator' => " n",
'before' => null,
'after' => null,
'escape' => false
));
echo $this->Paginator->next(__lang('Next') . ' »', array(
'class' => 'next',
'escape' => false
) , null, array(
'tag' => 'span',
'escape' => false,
'class' => 'next'
)), "n";
?>
每当用户单击分页链接时,我们都会发出 ajax 请求以获取内容并将现有内容替换为其 div 父级中的请求内容。参考我的完整视图文件代码(基于 Ajax 的分页和排序)
<div class="ajax-response">
<?php echo $this->element('paging_counter');?>
<table class="table table-striped table-bordered">
<tr>
<th rowspan="2" class="dl"><div class="ajax-pagination"><?php echo $this->Paginator->sort('name');?></div></th>
</tr>
<?php
if (!empty($countries)):
foreach ($countries as $country):
<tr>
<td class="dl"><?php echo $country['Country']['name'];?></td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td class="notice" colspan="19"><?php echo __lang('No countries available');?></td>
</tr>
<?php
endif;
?>
</table>
<?php if(!empty($countries)):?>
<div class="clearfix">
<div class="pull-right">
<?php echo $this->element('paging_links'); ?>
</div>
</div>
<?php endif;?>
</div>