when someone would immediatly scroll to the bottom after loading the code it would sometimes not update the id on time and load the same query heres my script
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript">
window.onscroll = function() {
if ((window.innerHeight + Math.ceil(window.pageYOffset)) >= document.body.offsetHeight) {
var lastId = $(".postid:last").attr("id");
var elem = document.getElementById("ele");
setTimeout(() => {
getMoreData(lastId);
elem.scrollIntoView();
}, 0);
}
}
function getMoreData(lastId) {
$(window).off("scroll");
$.ajax({
url: 'load_more.php?lastId=' + lastId,
type: "get",
beforeSend: function ()
{
$('.ajax-loader').show();
},
success: function (data) {
setTimeout(function() {
$('.ajax-loader').hide();
$("#post-list").append(data);
},1000);
}
});
}
</script>