Не могу понять, как сделать лимит на кол-во приходящих данных чистым xhr.
window.onload = function() {
var container = document.querySelector(".list"),
footer = document.querySelector("footer"),
images = [];
var xhr = new XMLHttpRequest(),
method = "GET",
endpoint = "https://jsonplaceholder.typicode.com/photos";
xhr.open(method, endpoint);
xhr.onreadystatechange = function() {
if (xhr.readyState === xhr.DONE && xhr.status === 200) {
images = JSON.parse(xhr.responseText);
addNewBox(images);
}
return images;
};
xhr.send();
function addNewBox(content) {
window.addEventListener("scroll", function() {
var x = footer.getBoundingClientRect().bottom - 100,
y = container.getBoundingClientRect().bottom,
c = window.innerHeight,
i;
if (y <= c) {
[].forEach.call(content, function(item) {
var el = document.createElement("div"),
img = document.createElement("img"),
text = document.createElement("span");
el.className = "box";
img.className = "img";
text.innerHTML = item.id;
img.setAttribute("src", item.url);
el.appendChild(text);
el.appendChild(img);
container.appendChild(el);
});
}
});
}
};
Как поставить limit, как в том же axios? Хелп ми, сомбади!