How to load view more comments using ajax and code

2020-03-05 03:07发布

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.

2条回答
兄弟一词,经得起流年.
2楼-- · 2020-03-05 04:01

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

查看更多
我只想做你的唯一
3楼-- · 2020-03-05 04:02

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)

查看更多
登录 后发表回答