I’m sending over 140 AJAX requests. The problem is that making 140 requests freezes the browser.
To fix this I want to make 10 requests and then on page scroll request 10 more.
var url = "https://xxxxxxx.com/search?name=" + searchWord + "&xxxs=" + duck + "&format=application/json";
jQuery.ajax({
url: url,
beforeSend: function() {
jQuery('#image').show();
},
complete: function() {
jQuery('#image').hide();
},
dataType: "text",
success: function(data) {}
});
I have tried this code:
var currentPageNumber = 1;
loadMore(currentPageNumber);
$(window).scroll(function() {
if($(window).scrollTop() == $(document).height()- $(window).height())
{
loadMore(currentPageNumber);
currentPageNumber +=1;
}
});
function loadMore(currentPage){
$.ajax({})
}
2
Answers
I guess you are talking about loading data rather than requests.
Its better to implement lazy loading and when we go the end of the page make a button stating “Load More” and again just increment it by 10.
Let’s say you do this in google:
You want next https://www.google.com/search?q=duck&start=10 so smth like: