window.onload = () => {
$.ajax({
type: "GET",
url: "/feed/ajax",
dataType: 'json',
success: function (data) {
if (data) {
const feedC = document.querySelector('.itemFeed')
data.forEach((arrayItem) => {
if (typeof arrayItem === 'object') {
const createFeedItem = document.createElement("div")
const feedI = createFeedItem.className = 'feed__container'
feedC.append(createFeedItem)
createFeedItem.innerHTML = '<img src="../../assets/image/feed/' + arrayItem.image + '">' +
'<div class="name_feed"><a href="feed/article/' + arrayItem.uid + '">'+ arrayItem.name +'</a></div>' +
'</div>'
}
})
}
},
error: function (r) {
console.log(r)
alert("Ошибка ajax");
}
});
}
let busy = false; // чтобы не накладывать запросы друг на друга
setInterval(function() {
if (busy) { return; }
busy = true;
$.ajax({
...
success: function (data) {
...
busy = false;
},
error: function (r) {
...
busy = false;
}
});
}, 5000);
(function load() {
$.ajax({
...
success: function (data) {
...
setTimeout(load, 5000);
},
error: function (r) {
...
setTimeout(load, 5000);
}
});
})();