How to load view more comments using ajax and code

2020-03-05 03:39发布

问题:

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 4 years ago.

How can you modify a Codeigniter default pagination to follow

----viewMore--- link style when loading for more record - AJAX way.

The thing is how do you make the div so auto expanding that like you handle a 10,000 record at a time.

回答1:

Try this

Make two Hidden Input in view

<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 your controller call 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 query in model with offset and limit



回答2:

You could use something like:

Example1

This is in core php, but you can understand the data flow and can make it then for MVC)

Also you can check this
Example

(Replace scroll event with button clicks)