title: CakePHP Ajax Pagination
body: <p>I am currently trying to get an ajax paginated list working. I think I'm close. When I click on the Previous, Next or individual page numbers, the correct results show but div.postsPaging is loaded with the paginated results along with Cake's default.ctp layout's header and footer. I've tried setting the layout to ajax in the displayPosts view or in the displayPosts action, but then the default layout doesn't appear at all (either inside or outside the div).</p>
  
  <p>My question is, how can I load the postsPaging div with just the paginated results and not the header, footer or anything else in the layout. How can I get the results of the ajax request to not include the header and footer of the default layout?</p>
  
  <p>The jQuery events attached to one of the page indexes and the Next button are:</p>
  
  <pre><code>$("#link-196981051").bind("click", function (event) {$.ajax({dataType:"html", success:function (data, textStatus) {$("#postsPaging").html(data);}, url:"\/AuthAdminCakeApp\/posts\/displayPosts\/page:2"});
  return false;});`
  
  $("#link-296431922").bind("click", function (event) {$.ajax({dataType:"html", success:function (data, textStatus) {$("#postsPaging").html(data);}, url:"\/AuthAdminCakeApp\/posts\/displayPosts\/page:2"});
  return false;});`
  </code></pre>
  
  <p>My PostsController code looks like this:</p>
  
  <pre><code>class PostsController extends AppController {
  
  public $helpers = array('Js' =&gt; 'Jquery');    
  public $paginate = array(
      'limit' =&gt; 3,
      'order' =&gt; array(
          'Post.title' =&gt; 'asc'
     )
  );
  
  public function displayPosts() {
      $this-&gt;set('posts', $this-&gt;paginate());
  }
  
  // other actions
  }
  </code></pre>
  
  <p>My paging element (paging.ctp) looks like this:</p>
  
  <pre><code>&lt;?php
  $this-&gt;Paginator-&gt;options(
          array('update'=&gt;'#postsPaging',
                  'url'=&gt;array('controller'=&gt;'posts', 
  'action'=&gt;'displayPosts')));
  ?&gt;
  &lt;table cellpadding="0" cellspacing="0"&gt;
  &lt;tr&gt;
      &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort('id'); ?&gt;&lt;/th&gt;
      &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort('user_id'); ?&gt;&lt;/th&gt;
      &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort('title'); ?&gt;&lt;/th&gt;
      &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort('body'); ?&gt;&lt;/th&gt;
      &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort('created'); ?&gt;&lt;/th&gt;
      &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort('modified'); ?&gt;&lt;/th&gt;
      &lt;th class="actions"&gt;&lt;?php echo __('Actions'); ?&gt;&lt;/th&gt;
  &lt;/tr&gt;
  
  &lt;?php
  foreach ($posts as $post): ?&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;?php echo h($post['Post']['id']); ?&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;
          &lt;?php echo $this-&gt;Html-&gt;link($post['User']['id'],     array('controller' =&gt; 'users', 'action' =&gt; 'view', $post['User']['id'])); ?&gt;
      &lt;/td&gt;
      &lt;td&gt;&lt;?php echo h($post['Post']['title']); ?&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo h($post['Post']['body']); ?&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo h($post['Post']['created']); ?&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo h($post['Post']['modified']); ?&gt;&amp;nbsp;&lt;/td&gt;
  
      &lt;td class="actions"&gt;
          &lt;?php echo $this-&gt;Html-&gt;link(__('View'), array('action' =&gt; 'view', $post['Post']['id'])); ?&gt;
          &lt;?php echo $this-&gt;Html-&gt;link(__('Edit'), array('action' =&gt; 'edit', $post['Post']['id'])); ?&gt;
          &lt;?php echo $this-&gt;Form-&gt;postLink(__('Delete'), array('action' =&gt; 'delete', $post['Post']['id']), null, __('Are you sure you want to delete # %s?', $post['Post']['id'])); ?&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php endforeach;  ?&gt;
  &lt;/table&gt;
  &lt;?php
  echo $this-&gt;Paginator-&gt;prev('&lt; ' . __('previous'), array(), null, array('class' =&gt; 'prev disabled'));
  echo $this-&gt;Paginator-&gt;numbers(array('separator' =&gt; ''));
  echo $this-&gt;Paginator-&gt;next(__('next') . ' &gt;', array(), null, array('class' =&gt; 'next disabled'));
  ?&gt;
  </code></pre>
  
  <p>The view for the displayPosts action looks like this:</p>
  
  <pre><code>&lt;div id="postsPaging"&gt;
  &lt;?php echo $this-&gt;element('Posts/paging'); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Edit:
  I'm using CakePHP 2.2.5.</p>