I had an infinite scroll page on my website. It was working just fine but now, I see that it doesn't load the first instance immediately on the page load. But when scrolled down, appears and infinite scroll also works.
I haven't imported anything or changed anything but suddenly happened on all browsers at the same time.
So is it related to any updates? And anyone has an idea how to resolve this? Here is the related javascript that loads the page as scrolled down.
<script type="text/javascript">
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
var start = 0;
var limit = 20;
var reachedMax = false;
var dnmID = getUrlVars()["donemID"];
var dvltID = 0;
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height() )
getData();
});
$(document).ready(function () {
getData();
});
function getData() {
if (reachedMax)
return;
$.ajax({
url: 'collection_data.php',
method: 'POST',
dataType: 'text',
data: {
getData: 1,
start: start,
limit: limit,
dnmID: dnmID,
dvltID: dvltID,
},
success: function(response) {
if (response == "reachedMax")
reachedMax = true;
else {
start += limit;
$(".results").append(response);
}
}
});
}
</script>