I'm playing around with the GitHub API and trying to build a simple app that lets you search for a GitHub user which then returns a list of that user's followers. I'm currently displaying the first 100 followers and would like each button click to load the next batch of 100 followers until all followers have been returned.
Since I'm loading the max count displayed on each page (100), I can access the second page by including '&page=2' at the end of the url. I just don't know how to automatically load each new page until there are no more followers to load.
Any advice on how to accomplish this? Any help is much appreciated.
// Make request to Github
$.ajax({
url:'https://api.github.com/users/'+username,
data:{
client_id:'9ecc0f206ecd34f2f552',
client_secret:'6eee17df91630a531ea2acf49848dec408079e9c'
}
}).done(function(user){
$.ajax({
url:'https://api.github.com/users/'+username+'/followers?per_page=100',
data:{
client_id:'9ecc0f206ecd34f2f552',
client_secret:'6eee17df91630a531ea2acf49848dec408079e9c'
}
}).done(function(followers){
$.each(followers, function(index, follower){
$('#followers').append(`
<div>
<div class="row">
<div class="col-md-10">
<img class="follower-avatar" src="${follower.avatar_url}" alt="" />
<p>${follower.login}</p>
</div>
<div class="col-md-2">
<a href="${follower.html_url}" target="_blank" class="btn">View profile</a>
</div>
</div>
</div>
`);
});
});
$('#profile').html(`
<div>
<div>
<div class="row">
<div class="col-md-3">
<img src="${user.avatar_url}">
<div>
<h3>${user.name}</h3>
</div>
<a target="_blank" class="btn" href="${user.html_url}">View Profile</a>
</div>
<div class="col-md-9">
<div>
<h1>Followers</h1> <br/>
<p>${user.followers}</p>
</div>
<div>
<h1>Followers</h1> <br/>
<p>2313123</p>
</div>
</div>
</div>
</div>
</div>
<h3 class="page-header">${user.name}'s followers</h3>
<div id="followers"></div>
`);
});