"use strict"
let requestCount = 0;
window.addEventListener('scroll', async () => {
const result = await getComment();
console.log(result);
});
function getComment() {
return new Promise(((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', `${document.URL}comments/${requestCount}/`);
xhr.onload = function () {
if (xhr.status === XMLHttpRequest.DONE) {
set_comment(...);
requestCount++;
resolve(xhr.response);
} else {
reject(xhr.status);
}
};
xhr.send();
}));
}
Изучите
Fetch API, это упростит жизнь