title: CodeIgniter pagination with Ajax
body: <p>I want to include pagination in my site operated by AJAX.</p>
  
  <p><strong>MY CONTROLLER</strong></p>
  
  <pre><code>public function get_details() {
      //pagination
      $config =   array(
          'base_url'          =&gt;  base_url()."exam/create/created/get_details/",
          'total_rows'        =&gt;  $this-&gt;exam-&gt;get_total(),
          'first_link'        =&gt;  "First",
          'last_link'         =&gt;  "Last",
          'per_page'          =&gt;  5,
          'uri_segment'       =&gt;  5,
          'full_tag_open'     =&gt;  "&lt;div id='ajax_pg' class='paginate'&gt;",
          'full_tag_close'    =&gt;  "&lt;/div&gt;",
          'num_tag1_open'     =&gt;  "&lt;a&gt;",
          'num_tag1_close'    =&gt;  "&lt;/a&gt;",
          'cur_tag_open'      =&gt;  "&lt;a class='current'&gt;",
          'cur_tag_close'     =&gt;  "&lt;/a&gt;",
          'next_tag1_open'    =&gt;  "&lt;a&gt;",
          'next_tag1_close'   =&gt;  "&lt;/a&gt;",
          'prev_tag1_open'    =&gt;  "&lt;a&gt;",
          'prev_tag1_close'   =&gt;  "&lt;/a&gt;",
          'first_tag1_open'   =&gt;  "&lt;a&gt;",
          'first_tag1_close'  =&gt;  "&lt;/a&gt;",
          'last_tag1_open'    =&gt;  "&lt;a&gt;",
          'last_tag1_close'   =&gt;  "&lt;/a&gt;"
      );
      $page=($this-&gt;uri-&gt;segment(5) != '') ? $this-&gt;uri-&gt;segment(5) : 0;
      $this-&gt;pagination-&gt;initialize($config);
  
      $data   =   array(
          'query' =&gt;  json_encode($this-&gt;exam-&gt;get_details($page, $config['per_page'])),
          'links' =&gt;  $this-&gt;pagination-&gt;create_links()
      );
  
      echo json_encode($data);
  }
  </code></pre>
  
  <p><strong>MY VIEW</strong></p>
  
  <pre><code>$(function() {
      paginate();
  
      function paginate() {
          $('#ajax_pg a').on('click', function() {
              var url = $(this).attr('href');
              alert(url);
  
              return false;
          });
      }
  });
  </code></pre>
  
  <p>Now the CI pagination is working all right but somehow or the other the ajax jQuery click event i not firing.</p>
  
  <p>Thanks in advance.</p>