CakePHP 1.2.x-Ajax分页“下一页”未更新,停留在2 [英] CakePHP 1.2.x - Ajax Pagination 'Next Page' Does Not Update, Stays on 2

查看:75
本文介绍了CakePHP 1.2.x-Ajax分页“下一页”未更新,停留在2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切顺利,

我在使用CakePHP 2.x时非常自在,但目前必须在一个更老的CakePHP 1.2.x应用程序上工作。

I am extremely comfortable in using CakePHP 2.x but am having to work on a much older CakePHP 1.2.x app at the moment.

我已经实现了Ajax分页,该分页在第一页上工作得很好,但是下一页链接永远不会超过第二页。所以即使第二页一次加载后,我的分页器的下一个链接仍然为'page:2'。

I have implemented an Ajax pagination, which works perfectly fine for the first page, however the 'Next Page' link never does go past page 2. So even once page 2 is loaded, my paginator's next link still remains 'page:2'.

区别是我的分页器链接为GLOBAL。我不会将分页链接作为新的DOM注入HTML的一部分加载。分页器链接位于我的ajax容器之外,单击时将内容加载到容器中。分页器链接未加载到该容器中。

The difference is that my paginator links are GLOBAL. I do not load the pagination links as part of the new DOM injected HTML. The paginator links sit outside of my ajax container, and the content is loaded into the container on click. The paginator links are NOT loaded into that container.

我很清楚CakePHP 2.x使用了 $ this-> Js-> ; WriteBuffer(); 方法打印出核心JS,据我所知(除其他外)它用于更新分页链接。

I am well aware that CakePHP 2.x employs the $this->Js->WriteBuffer(); method to print out core JS, which as far as I know is used (amongst other things) to update the pagination links.

据我所知,CakePHP 1.2.x没有这种方法。

CakePHP 1.2.x to my knowledge does not have such a method.

有人可以对此发表一些看法或提出意见吗?

Can anyone shed some light or offer some opinions on this?

我包含的组件&助手:

My included components & helpers:

var $components = array('RequestHandler');
var $helpers = array('Javascript', 'Html', 'Form', 'Paginator');

我的分页:

$paginator->next('<h3>Next Page </h3>',array('escape'=>false));

我有一个Ajax视图和这些Ajax加载的Ajax布局。 Ajax视图仅包含我要加载的内容,实际上只是循环。 Ajax布局仅是<?php echo $ content_for_layout?>

I have an Ajax view and an Ajax layout for these ajax loads. The Ajax view just contains the content I want to load, literally just the loop. The ajax layout is ONLY a single line of <?php echo $content_for_layout ?>

的一行这在我的ajax布局的末尾,但无济于事:

I have placed this at the end of my ajax layout, but to no avail:

<?php echo $javascript->writeEvents(); ?>

任何帮助都会得到极大的赞赏。

Any help will be mega appreciated.

Simon

更新:在头部添加JS代码,并在Ajax中添加视图代码

UPDATE: Adding JS code in head, and Ajax view code

头戴式JS:

$javascript->link('jquery-ui-1.8.13.custom.min.js', false);
$javascript->link('scrollads.js', false);
$javascript->link('jquery.form.js', false);
$javascript->link('jquery.form-defaults.js', false);
$javascript->link('jquery.jplayer.min.js', false);
$javascript->link('jquery.sparkline.min.js', false);

$ javascript-> link(‘jquery.cookie.js’,false);
$ javascript-> link(‘jquery.tweet.js’,false);
$ javascript-> link(‘flowplayer.min.js’,false);
$ javascript-> link('jquery.validate.min.js',false);
$ javascript-> link(‘coin-slider.min.js’,false);
$ javascript-> link('jquery.thslide.min.js',false);
$ javascript-> link(’jquery.barousel.min.js’,false);
$ javascript-> link('behaviour.js',false);
echo;
echo;
echo jQuery.noConflict();;

$javascript->link('jquery.cookie.js', false); $javascript->link('jquery.tweet.js', false); $javascript->link('flowplayer.min.js', false); $javascript->link('jquery.validate.min.js', false); $javascript->link('coin-slider.min.js', false); $javascript->link('jquery.thslide.min.js', false); $javascript->link('jquery.barousel.min.js', false); $javascript->link('behaviour.js', false); echo ""; echo ""; echo "jQuery.noConflict();";

echo $asset->scripts_for_layout();

Ajax查看文件:

<?php foreach ($galleries as $gallery): ?>
                <div class="albumcontainer-wrapper">
                    <div class="albumcontainer-top"></div>
                        <div class="albumcontainer">
                            <a href="<?php echo Router::url('/gallery_images/index/'.$gallery['Gallery']['id']); ?>">
                                <?php echo $html->image($gallery['GalleryImage'][0]['Image']['default']['path_adjusted']); ?>
                            </a>
                            <h3><?php echo $gallery['Gallery']['title']; ?></h3>
                        </div>
                    <div class="albumcontainer-bottom"></div>
                </div>
            <?php endforeach; ?>
            <?php echo $javascript->WriteEvents(true); ?>

这是我将ajax加载视图附加到现有内容上而不是替换它的方法:

$paginator->options(
                    array(
                        'update' => 'ajaxAppendGalleries', 
                        'indicator' => false,
                        'evalScripts' => true,
                        'complete' => 'var tmp = jQuery("#ajaxAppendGalleries").html(); jQuery("#galleryContainer").append(tmp); tmp = null; jQuery("#ajaxAppendGalleries").empty();',
                        )
                    ); 


推荐答案

西蒙(Simon),怀疑发生的事情是您的点击事件是在document.ready()时绑定到原始DOM对象,因此,当您进行Ajax调用并替换了分页的内容时,事件不会附加到替换的DOM对象上。

Simon, suspect whats happening is that your click events are being bound to the original DOM object when document.ready(), so when your Ajax call occurs and the paginated content is replaced, the events aren't attached to the replacement DOM object.

我知道在jQuery中您可以使用

I know in jQuery you can use the

$(document).on('event','#target',function(){})

语法,以确保该事件永久绑定到页面上的所有对象,无论它们何时加载以及如何加载和我确实在蛋糕食谱中看到了一个例子a>(今天向下滚动到Js :: event),建议您可以使用它……尽管请注意,在当前版本的jQuery中不赞成使用.bind()方法,而应使用.on()。恐怕我不知道在1.2中是否可行,但是如果需要的话,您可以使用一些手动jQuery来扩展使用此JS帮助器。

syntax to ensure that the event is permanently bound to all objects on the page, regardless of when/how they load and I did see an example in the Cake Cookbook (scroll down to Js::event) today that suggested you could use it ... although note the .bind() method is deprecated in current version of jQuery, use .on() instead. I'm afraid I don't know if that's possible in 1.2, but you could augment your use of this JS helper with some manual jQuery if you had to.

这篇关于CakePHP 1.2.x-Ajax分页“下一页”未更新,停留在2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆