How to load more comments with ajax and codeigniter
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 to share