title: Codeigniter: How to fix pagination links, not updating when clicked, using ajax
body: <p>I'm trying to put pagination links into my website using ajax to keep the page from refreshing. I managed to make it work but the pagination links are not updating. When I click on the next page, the page will load but the pagination link will stay on page 1. I tried putting <code>$this-&gt;pagination-&gt;create_links();</code> inside a variable and echo it inside a div but its showing nothing. Here are my codes:</p>
  
  <p>model:</p>
  
  <pre><code>public function get_posts($limit = FALSE, $rowno = FALSE)
          {
              if($limit)
              {
                  $this-&gt;db-&gt;limit($limit, $rowno);
              }
  
              $this-&gt;db-&gt;select('*, posts.image AS post_image, posts.id AS post_id, posts.user_id AS post_user_id');
              $this-&gt;db-&gt;from('posts');
              $this-&gt;db-&gt;join('categories', 'categories.id = posts.category_id');
              $this-&gt;db-&gt;join('users', 'users.id = posts.user_id');
              $this-&gt;db-&gt;order_by('posts.created_at', 'DESC');
  
              $query = $this-&gt;db-&gt;get();
              return $query-&gt;result_array();
          }
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>public function index()
          {
              // pagination page number
              $pageno = $this-&gt;input-&gt;post('pageno');
  
              // pagination config
              // $config['base_url'] = base_url()."posts/index";
              $config['base_url'] = '#';
              $config['total_rows'] = $this-&gt;db-&gt;count_all('posts');
              $config['per_page'] = 2;
              $config['num_links'] = 3;
              $config['attributes'] = array('class' =&gt; 'pagination-class');
              $config['full_tag_open'] = '&lt;div id="paginator"&gt;';
              $config['full_tag_close'] = '&lt;/div&gt;';
  
              $data['posts'] = $this-&gt;post_model-&gt;get_posts($config['per_page'], $pageno);
              $data['title'] = 'Latest Posts';
  
              $data['pagination'] = $this-&gt;pagination-&gt;create_links();
              $data['row'] = $pageno;
  
              // init pagination
              $this-&gt;pagination-&gt;initialize($config);
  
              $this-&gt;load-&gt;view('posts/index', $data);
  
          }
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>&lt;div id="pagination"&gt;
              &lt;?php echo $this-&gt;pagination-&gt;create_links(); ?&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>ajax:</p>
  
  <pre><code>$('#paginator').on('click', 'a', function(e) {
          e.preventDefault();
  
          var pageno = $(this).attr('data-ci-pagination-page');
  
          $.ajax({
              data : { 'pageno' : pageno },
              method : 'post',
              // dataType : 'json',
              url : base_url + 'posts/index',
              success : function(response) {
                  $("#main_container").html(response);
              }
          });
  </code></pre>