My Logic
- REST API fetch record from custom list
- I fetch top 6 records, while I fetch record I will get one more jSON node which will have forward paging URL. I am assigning this URL to HTML5 button to data-url attribute.
- Then I will get that data-url on button click, I use this URL to repeat point 1-3. I will repeat above process until paging URL is not undefined
My Code
$.when(processList(url)).done(function () { });
function processList(nextUrl) {
var dfd = new $.Deferred();
if (nextUrl == undefined) {
$("#btnViewMore").hide();
dfd.resolve();
return;
}
var news = ""
getData(nextUrl).done(function (data) {
var items = data.d.results;
var next = data.d.__next;
$("#btnViewMore").removeAttr("data-url").attr("data-url", next).show();
dfd.resolve();
// $.when(processList(next)).done(function () {
// dfd.resolve();
// });
$.each(items, function (i, item) {
// display record
})
$("#news").append(news);
})
return dfd.promise();
}
Button Click
$("#btnViewMore").click(function () {
var _url = $(this).data('url')
$.when(processList(_url)).done(function () { });
})
My HTML5 Button
<button type="button" name="" id="btnViewMore" class="btn btn-primary btn-lg btn-block" style="display:none">View More
<i class="fa fa-arrow-circle-down" aria-hidden="true"></i>
</button>
Now my issue if I run full record fetch with $.when inside getData it will bring all records properly. But when I assign url to button then it start repeating same record again and again. I found out that URL is not changing with new URL due to that it is repeating data
Please let me know how can I solve this