title: How to make the pagination class in Codeigniter work with AJAX?
body: <p>I have a table loaded via AJAX and along with the table the pagination is also loaded through AJAX. The table contains a list of all users on my site limited to 30 at a time.</p>
  
  <p>This is how I'm returning the response to the JavaScript from the controller:  </p>
  
  <pre><code>    $users = $this-&gt;users_m-&gt;get_users($type, $offset);
      $num_rows = $this-&gt;users_m-&gt;user_stats($type);
  
      $config['per_page'] = 30;
      $config['num_links'] = 5;
      $config['total_rows'] = $num_rows[0];
      $this-&gt;pagination-&gt;initialize($config);
  
      echo json_encode(array(
          'users' =&gt; $users,
          'pagination' =&gt; $this-&gt;pagination-&gt;create_links()
      ));
  </code></pre>
  
  <p>All is well except the pagination is never correct. The first time it is but on subsequent requests it is not.</p>
  
  <p>When using the pagination class in a non AJAX page, the page number I click becomes the active one. Here page 1 is always active (surrounded by <code>&lt;strong&gt;</code> tags as opposed to being a link). Secondly the numbers never change. I get:</p>
  
  <pre><code>[1] [2] [3] [4] [5] [6] [&gt;] [Last &gt;]
  </code></pre>
  
  <p>every time. Even if I click last I get the same numbers back, it doesn't change.</p>
  
  <p>How to get the pagination class to work with AJAX?</p>