Reputation: 4180
So, I'm trying to get a list of all issues in my repository. The problem is that I don't know how to access the response header, and grab the other pages. What I have so far is:
var outhtml;
var repositories;
$.getJSON(uploadURL, function(json){
repositories = json;
outputPageContent();
});
function outputPageContent() {
if(repositories.length == 0) { outhtml = outhtml + '<p>No repos!</p></div>'; }
else {
//console.log(repositories);
outhtml = outhtml + '<p><strong>Repos List:</strong></p> <ul>';
$.each(repositories, function(index) {
console.log(repositories[index]);
outhtml = outhtml + '<li><a href="'+repositories[index].html_url+'" target="_blank">'+repositories[index].title + '</a></li>';
});
outhtml = outhtml + '</ul></div>';
}
$('#ghapidata').html(outhtml);
}
but this only gets me the first page. I've done pagination to get issues before, but it was with python. How do I do it with js/jquery?
Upvotes: 2
Views: 386
Reputation: 4180
Ok I figured it out, the headers are returned in the actual Ajax call. So I needed to assign it to a variable and then use "getResponseHeader()"
Basically:
var issues =[];
var ajsponse;
function buildIssueList(githubURL){
ajsponse = $.ajax({
dataType: "json",
type: 'GET',
url: githubURL,
success: function(data){
$.merge(issues, data);
var link = ajsponse.getResponseHeader("Link");
if (link.indexOf("next") !== -1) {
githubURL=link.substring(link.indexOf("<")+1,link.indexOf(">"));
buildIssueList(githubURL);
}
else{
printcompiled(issues);
}
}
});
}
Upvotes: 1