Monday, August 30, 2010

Re: Ajax Pagination cakePHP 1.3 and jQuery // enable the RequestHandler component

In the end, the following solution works for me:

1. Modify jquery_engine.php as suggested by ecommy.com:

jquery has live event feature to acomplish that copy
cake/libs/view/helpers/jquery_engine.php to
app/views/helpers/jquery_engine.php
now open jquery_engine.php and on line 181 change the code from:
return sprintf('%s.bind("%s", %s);', $this->selection, $type,
$callback);
to
return sprintf('%s.live("%s", %s);', $this->selection, $type,
$callback); //ecommy.com modified code

2. Adding the writeBuffer at the bottom of the Ajax element:
echo $this->Js->writeBuffer();
as mentioned by many others,

and finally

3. Adding the component RequestHandler in the controller:
var $components = array('RequestHandler');

Without having enabled the RequestHandler, the steps above are
effectless.

Best,
Heiko


On 4 Aug., 20:39, bradmaxs <b...@pezzano.com> wrote:
> Thank you for your help.  I added the file to the helpers and changed
> the code and nothing changed:(
>
> Before I had the pagination outside of the element and now I have
> moved it inside the element and it seems to have made a change.
>
> Before it worked but only if I clicked on the numbers or like I
> explained if I clicked on next but only the first time.  Now it seems
> to work every other link.  So when I go to the page and click on the
> next it goes to the next page without a refresh.  If I click on next
> to go to the third page it does do that within the links but it
> refreshes the page.  So I am getting every other page by ajax.
>
> Here is the javascript at the bottom.  It still says bind even though
> I added the helper with the changed code.  Is this correct looking.
>
> <script type="text/javascript">
> //<![CDATA[
> $(document).ready(function () {$("#link-1109729578").bind("click",
> function (event) {$.ajax({dataType:"html", success:function (data,
> textStatus) {$("#comment").html(data);}, url:"\/thegarage\/view\/22\/
> page:2"});
> return false;});
> $("#link-922906323").bind("click", function (event)
> {$.ajax({dataType:"html", success:function (data, textStatus) {$
> ("#comment").html(data);}, url:"\/thegarage\/view\/22\/page:1"});
> return false;});
> $("#link-1486848737").bind("click", function (event)
> {$.ajax({dataType:"html", success:function (data, textStatus) {$
> ("#comment").html(data);}, url:"\/thegarage\/view\/22\/page:2"});
> return false;});});
> //]]>
> </script>
>
> Thank you so much for helping.
>
> Brad
>
> On Aug 3, 11:42 pm, "ecommy.com" <bstdevelopm...@gmail.com> wrote:
>
> > This is a common problem - and is because jquery doesn't work similar
> > with prototype when it comes to executing ajax code inside a page that
> > was requested by ajax
>
> > jquery has live event feature to acomplish that copy
> > cake/libs/view/helpers/jquery_engine.php to
> > app/views/helpers/jquery_engine.php
>
> > now open jquery_engine.php and on line181change the code from:
>
> > return sprintf('%s.bind("%s", %s);', $this->selection, $type,
> > $callback);
>
> > to
>
> > return sprintf('%s.live("%s", %s);', $this->selection, $type,
> > $callback); //ecommy.com modified code
>
> > On Aug 4, 12:06 am, bradmaxs <b...@pezzano.com> wrote:
>
> > > I have set up pagination following the Mark Story article and it seems
> > > to work fine EXCEPT my next, previous and number links are not
> > > updating.
>
> > > If I click on next after the first page load, it goes to the next
> > > comment (cool), however the next link does not update to the third
> > > page and just stops working.  I can use the number links to each page
> > > and they work fine but they don't update either so I can never get
> > > back to page 1 without a refresh and you never know where you are.
>
> > > Here is lies the rub.  I am using one model for the main content of
> > > the page and contain for the comments.  Here is my controller code.
>
> > > // VIEW
> > >         function view($id = null) {
> > >                 if (!$id) {
> > >                         $this->Session->setFlash(sprintf(__('Invalid %s', true), 'cshow'));
> > >                         $this->redirect(array('action' => 'index'));
> > >                 }
> > >                 $this->set('cshow', $this->Cshow->read(null, $id));
> > >                 $this->paginate = array(
> > >                         'contain' => array(
> > >                                 'User' => array(
> > >                                         'UserPreference.image'
> > >                                 ),
> > >                         ),
> > >                         'fields' => array(
> > >                                 'CshowComment.id', 'CshowComment.user_id', 'CshowComment.comment',
> > > 'CshowComment.created', 'User.id', 'User.username'
> > >                         ),
> > >                         'conditions' => array(
> > >                                 'CshowComment.cshow_id' => $id
> > >                         ),
> > >                         'recursive' => 0,
> > >                         'limit' => 1,
> > >                         'order' =>  array(
> > >                                 'CshowComment.created' => 'desc'
> > >                         )
> > >                 );
> > >                 $this->set('cshowComment', $this->paginate('CshowComment'));
> > >                 if ($this->RequestHandler->isAjax()) {
> > >                         $this->render('/elements/comments');
> > >                         return;
> > >                 }
> > >                 $this->set('title_for_layout', 'eGarage.tv - View The Garage Show');
> > >         }
>
> > > In the view:
>
> > > <div id="comment">
> > > <?php echo $this->element('comments'); ?>
> > > </div>
> > > <div class="clear spacer"></div>
> > > <div class="paging">
> > > <?php $paginator->options(array('update' => '#comment')); ?>
> > > <?php echo $this->Paginator->prev('<< '.__('previous', true), array(),
> > > null, array('class'=>'disabled'));?> | <?php echo $this->Paginator->numbers();?> |
>
> > > <?php echo $this->Paginator->next(__('next', true).' >>', array(),
> > > null, array('class' => 'disabled'));?> <?php echo $this->Paginator->counter(array('format' => __('%page% of %pages%, %count% Comments',
>
> > > true)));?>
> > > </div>
>
> > > and I have included theJshelper and the RequestHandler component in
> > > my appController as well as <?php echo $this->Js->writeBuffer();  ?>
> > > in my default layout right before the </body> tag.
>
> > > Not sure if this could be the problem but I am serving jQuery from a
> > > CDN and not from the webroot/jsfolder.
>
> > > I am using an element because if I don't the page duplicates the
> > > content that I am trying to update instead of loading via AJAX.  This
> > > may be the problem but I am stuck.
>
> > > I can post other code if this doesn't tell the whole story.
>
> > > Thanks in advance.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: