How to load more comments with ajax and codeigniter

How can you change the default breakdown for Codeigniter to follow

---- viewMore --- link style on load for more post - AJAX way.

The point is, how you make the div auto-expand, as if you were processing 10,000 records at a time.

+3


source to share


2 answers


try it

Make two hidden inputs

<button type="button" onclick="loadmore()" value="loadmore" >Load More</button>
<input type="hidden" name="limit" id="limit" value="10"/>
<input type="hidden" name="offset" id="offset" value="20"/>

      

Ajax call



function loadmore(){
    $.ajax({
        url:your_controller/loadmore,
        data:{
          offset :$('#offset').val(),
          limit :$('#limit').val()
        },
        type:json, 
        success :function(data){
            $('#load-more').prepend(data.view)
            $('#offset').val(data.offset)
            $('#limit').val(data.limit)
        }
    })
}

      

In the controller management model

 function loadmore(){
      $limit = $this->input->get('limit');
      $offset = $this->input->get('offset');
      $this->load->model('yourmodel');
      $result  = $this->yourmodel->getdata($offset,$limit);
      $data['view'] = $result;
      $data['offset'] =$offset +10;
      $data['limit'] =$limit;
      echo json_encode($data);
    }

      

write a query in the model with offset and limit

+3


source


You can use something like:

Example 1

It's mostly php, but you can understand data flow and can do it for MVC)



Also you can check this Example

(Replace button click scroll event)

+1


source







All Articles