Почему ajax запрос срабатывает сразу несколько раз?
$(window).scroll(function () {
let height_win = false;
if ($(window).height() + $(window).scrollTop() >= $(document).height() - 200 && !height_win) {
height_win = true;
indexcat = $('.news_category.active').index() + 1;
$.ajax({
url: '/modal?route=news/id=' + indexcat,
type: 'GET',
data: {},
dataType: 'JSON',
success: function success(response) {
if (response.data != "") {
if (response.data.length > 0) {
var el = $(response.data);
$("#news").append(el).masonry('appended', el, true);
}
height_win = false;
}
}
});
}
});
Но если в условии сделать просто:
if ($(window).height() + $(window).scrollTop() >= $(document).height() && !height_win) /* скролить полностью до конца страницы
То все работает хорошо.