在cakephp 2.0中进行Ajax分页/排序

时间:2012-02-17 12:56:45

标签: cakephp cakephp-2.0

我正在使用cakephp 2.0并尝试创建ajax分页,我在阅读的文档中无法通过此

$this->Paginator->options(
                          array('update'=>'#box',
                                'evalScripts' => true,
                                'before' => $this->Js->get('#loaderIDast')->effect('fadeIn', array('buffer' => false)),
                                'complete' => $this->Js->get('#loaderIDast')->effect('fadeOut', array('buffer' => false)),
                          ))
在视图中

将使paginaton助手创建一个在我的情况下不会的ajax链接。 我在这里使用jQuery引擎。

在挖掘库文件时,我发现paginator正在使用正在进行此事件的事件函数

jQuery("#link-969794460").bind("click", function (event) {jQuery.ajax({beforeSend:function (XMLHttpRequest) {jQuery("#loaderIDast").fadeIn();}, complete:function (XMLHttpRequest, textStatus) {jQuery("#loaderIDast").fadeOut();}, dataType:"html", evalScripts:true, success:function (data, textStatus) {jQuery("#box").html(data);}, url:"\/admin\/user\/manage_user\/sort:User.name\/direction:asc"}); return false;});

并且在事件调用中以某种方式不会返回。我不知道为什么有人知道我错过了什么?

此致 Himanshu Sharma。

3 个答案:

答案 0 :(得分:4)

实际上,书中有here的例子。查找Ajax分页部分。确保遵循所有指示并且它将起作用。

你需要:

  • 要在控制器中加载的RequestHandler组件。
  • 将Js Helper加载到您的控制器中。
  • 您需要在视图/布局中包含jQuery。
  • 您需要在视图/布局中编写Js缓冲区($this->Js->writeBuffer())。除非您在AppController中加载Js帮助器,否则建议将其放在您的视图中,否则将无法定义$this->Js

本书中的示例使用jQuery并且可以工作。

答案 1 :(得分:1)

在告诉分页助手你想要一个javascript链接而不是普通的html

之后,请不要忘记添加$ this-> Paginator-> numbers()
    <?php
$this->Paginator->options(array(
        'update' => '#content',
        'evalScripts' => true,
        'before' => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer' => false)),
        'complete' => $this->Js->get('#busy-indicator')->effect('fadeOut', array('buffer' => false)),
    ));
    ?>
    <?php echo $this->Paginator->numbers();?>

答案 2 :(得分:1)

我有同样的问题,但在我的情况下,布局文件中div标签的ID是错误的。它应该是“内容”。

相关问题