Utilizing the REST API of SharePoint 2010, I am retrieving data from a list that has a maximum item limit of 1000. If a list contains more than 1000 items, the response will include a key named d.__next which provides the URL for fetching the next set of results. An example URL format is:
https://{SiteURL}}/_vti_bin/listdata.svc/{listName}/?$skiptoken=1000
Initially, I assumed there would be fewer than 3000 items in the list, so I nested requests multiple times as shown in this code snippet:
$http({
method: 'GET',
url: jsonLocation,
headers: {
"Accept": "application/json;odata=verbose"
}
}).then(function successCallback(
response) {
$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 now need to fetch data from a list with over 40,000 items, and the current approach is no longer practical.
The challenge lies in finding a way to loop through the requests while utilizing $http's asynchronous callbacks and checking for the existence of d.__next within the response data during the success callback.
What would be the most effective strategy to address this issue?