pagination canvas api with php ajax

vinhnq
Community Novice

connect.php below:

<?php
$curl = curl_init();

$token = "dddddddddQej5jBa1lbt76pG5";
$pageNo = 0;

function curlCall($curl, $endpoint, $token,$pageNo){
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://lsts.instructure.com/api/v1' . $endpoint . '?access_token=' . $token . '&per_page=100&page=' . $pageNo
));
}

$endpoint = "/accounts/1/users";

do{
$pageNo++;
curlCall($curl, $endpoint, $token, $pageNo);
$resp = curl_exec($curl);
$json = json_decode($resp);
//Process $json here
print "<-|->".json_encode($json)."<-|->";
}while(sizeof($json) > 0);

$pageNo = 0;
?>

list.php below

<button id="loadmore">Load More</button>
<div id="pageno"></div>
<table id="getdanhsachhocsinh" border="1" style="width:100%;">
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>created date</th>
<th>studen_number</th>
<th>login_number</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
loadmore();
$('#loadmore').click(function(){
$("#getdanhsachhocsinh tbody").html('');
loadmore();
});
function loadmore(){
$.ajax({
type: 'POST',
url:'connect.php',
processData: false,
contentType: false,
success: function(data){
var arr = JSON.parse(data.split("<-|->")[1]);
var msg = '';
var ine = 1;
for(var i=0; i<arr.length; i++){
var d = new Date(""+arr[i].created_at+"");
var day=d.getDate();
var month=d.getMonth()+1;
var year=d.getFullYear();
var datenew = ""+month+"-"+day+"-"+year+"";
msg += '<tr>';
msg += '<td>'+arr[i].id+'</td>';
msg += '<td>'+arr[i].name+'</td>';
msg += '<td>'+datenew+'</td>';
msg += '<td>'+arr[i].sis_user_id+'</td>';
msg += '<td>'+arr[i].login_id+'</td>';
msg += '<tr>';
ine = ine+1;
}
$("#getdanhsachhocsinh tbody").html(msg);
},
});

}
});
</script>

how to show all rows on list.php ??? it just get 100 rows and stop.

0 Likes