ajaxcakephppagination

In CakePHP, layout calling two times when I use AJAX


Please see below code snippt:

<?php
  //Sets the update and indicator elements by DOM ID
  $paginator->options(array('update' => 'content','indicator' => 'spinner','url' =>$this->passedArgs));

  echo $paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
  echo $paginator->next('Next >>', null, null, array('class' => 'disabled'));
?>

And my page URL is http://total.projectsjunction.com/artists/portfolios/1

Now I have a problem.I am using AJAX based paging with CakePHP But when I click on next page it calling header and footer two times.

How I can call layout only one time if I use function two time with AJAX.


Solution

  • Something like this may help you:

    if( $this->RequestHandler->isAjax() ) {
      $this->layout = false;
    }
    

    This will turn off the layout on an ajax request but leave it on otherwise. I believe this will be specific to a given request, but I haven't tested it and have never needed to do this myself.