【问题标题】:CakePHP Ajax pagination problemsCakePHP Ajax 分页问题
【发布时间】:2013-03-26 22:51:34
【问题描述】:

我正在使用 cakephp 2.2.2,我想创建一个简单的 ajax 分页。我正在关注这个(http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#ajax-pagination),但我似乎无法让它正常工作。当我加载页面时有时它使用 ajax 有时它不使用,在 IE 10 中我也得到了一些奇怪的东西,比如整个菜单折叠到设置为更新的 div 中。

这是我所做的:

  1. echo $this->Html->script('jquery'); 放在我的布局文件的<head> 中。
  2. 在我的控制器中包含 RequestHandler 组件和 Js 助手。
  3. 把它放在我的视图文件的开头:

    $this->Paginator->options(array( 'update' => '#content', 'evalScripts' => true ));

  4. 把它放在布局文件底部</body>之前: echo $this->Js->writeBuffer();

  5. 然后我通常像这样使用分页器:

    echo $this->Paginator->sort('id');

谁能告诉我我是否遗漏了什么或哪里出了问题,因为我真的不知道我做错了什么。 非常感谢。

【问题讨论】:

    标签: ajax cakephp pagination


    【解决方案1】:

    只需将此代码从您的 view 文件移动到您的 layout

    $this->Paginator->options(array( 'update' => '#content', 'evalScripts' => true ));
    

    【讨论】:

      【解决方案2】:

      我在分页中也遇到了同样的问题。

      我找到了一个临时解决方案。 在控制器函数中,添加以下代码来设置标志变量。

       if($this->request->is('ajax')){
              $this->set('paginate',true);
          }
      

      然后在视图中,你需要隐藏#content div下以外​​的部分。

      <?php if(!isset($paginate)):
          // Code above # content div including the start of div
      endif:?>
      
      Pagination code inside the content div
      
      <?php if(!isset($paginate)):
          // Code below # content div including content of div
      endif:?>
      

      附:逻辑是当分页完成后,其他部分将不会显示在分页视图中。

      【讨论】:

      • 谢谢,我会在一两天内再次尝试这个项目,但是你认为这解决了一次浏览器重新加载的问题(就像没有 ajax 一样),另一次它没有重新加载(就像有ajax一样)。这仅在使用分页时才会发生,我自己配置​​和使用的所有其他 ajax 东西都可以完美运行。或者这仅对我有时会弄乱 div 的部分有帮助?
      猜你喜欢
      • 1970-01-01
      • 2016-12-25
      • 1970-01-01
      • 2012-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-22
      相关资源
      最近更新 更多