I am fetching data using the REST API of SharePoint 2010 which has a maximum list item limit of 1000. When fetching a list with greater than 1000 items the response data will have a key called d.__next that contains the URL for the next set of results. For example:
https://{SiteURL}}/_vti_bin/listdata.svc/{listName}/?$skiptoken=1000
I had initially assumed that there would be always less than about 3000 items in the list so I just nested the requests a few times like in this example:
$http({
method: 'GET',
url: jsonLocation,
headers: {
"Accept": "application/json;odata=verbose"
}
}).then(function successCallback(
response) {
// console.log(response.data.d)
$scope.ListData = response.data.d.results;
if (typeof(response.data.d.__next) != "undefined") {
$http({
method: 'GET',
url: response.data.d.__next,
headers: {
"Accept": "application/json;odata=verbose"
}
}).then(function successCallback(
response) {
$scope.ListData.concat(response.data.d.results);
}, function errorCallback(response) {
/* */
console.log("HTTP Get Failed");
});
} else {
executeFunction($scope.ListData)
}
},
function errorCallback(response) {
/* */
console.log("HTTP Get Failed");
});
However I have to now fetch of a list which contains 40 thousand plus items and it's no longer really feasible to do this bit of a hack.
My issue is that I can't figure out how to put the request in any sort of a loop because of $http's asynchronous callback and because I need to check the existence of d.__next inside the response data inside the success callback.
What would be the best way of going about doing this?