I am trying to create a loadmore button. If clicked it must load next records appended to previous one. Here is my controller class
class Sample extends CI_Controller{
function wall($start)
{
$start = $this->input->post('start');
$resultjson = $this->curl->simple_get("http://www.mywebsite.com/api/posts.php?start=$start&count=10");
$resultant_data = json_decode($resultjson,true);
$data['sample'] = $resultant_data;
$this->load->view('posts',$data);
}
}
In My view
<html>
<head>
<I have some js files such as masonry>
<script type="text/javascript">
function loadmore()
{
$.ajax({
type:"POST",
url:"http://www.server.com/application/index.php/Sample/wall/",
data :"start=10",
//dataType : 'json',
success: function (data) {
alert(data);
}
});
}
</script>
</head>
<body>
. . . . .
. . . . .
<div id="loadmore" style="margin-top:75%;">
<input type="button" value="loadmore" onclick="loadmore()">
</div>
</body>
</html>
Sample is class name and wall is method name The problem is if i directly call www.mysite.com/application/sample/wall/10 in the url it gives me next 10 records.... But i am unable to display next ten records if clicked on the loadmore button. i.e if i call www.mysite.com/application/sample/wall i will be getting 0 to 10 and a loadmore button. When button is clicked it must display next ten as well as the earlier data. Can anyone please help me
load www.mysite.com/application/sample/wall/0 at first(default), and same as your code.
or
add if($start == ''){$start = 0;}
in your controller.