let url = "your/api/endpoint";
let limit = 1000; //chunk size per 1 request
let resultData = [];
function loadChunk(from) {
ajax(`${url}?limit=${limit}&from=${from}`, function success(chunkOfData) {
resultData.push(chunkOfData);
if(chunkOfData.length == limit) loadChunk(resultData.length);
})
}
loadChunk(0);
// js
let filterButtons = document.querySelectorAll(".portfolio__gallery-filters a")
filterButtons.forEach(button => {
button.addEventListener("click", function() {
alert(this.getAttribute("href"))
})
})
// jquery
$(".portfolio__gallery-filters a").click(function(e) {
e.preventDefault();
let href = $(this).attr("href");
alert(href);
})
async (req, res) => {
...
try {
let article = await newArticle.save();
let section = await Section.findOneAndUpdate({ _id: article.section }, {$push: {"articles": article._id}}, {new: true});
if (section === null) return res.json({ message: 'No sections found' });
res.status(201).json({
status: 'OK',
article
});
}
catch(e) {
console.log(e);
next(e);
}
screen.availHeight
let element = document.querySelector("Ваш элемент");
document.onscroll = () => {
let percent = ( screen.availHeight - window.pageYOffset / 2 ) / screen.availHeight;
if(percent <= 0) element.style.opacity = 0;
else element.style.opacity = percent;
console.log(percent);
};
exports.getPerson = function(id) {
return new Promise((resolve, reject) => {
// Любая асинхронная операция. Например:
sql.query(`select * from users where id='${id}'`, data => {
// Если запрос произошел успешно
resolve(data);
}, error => {
// Если с ошибкой
reject(error);
});
});
};
let {getPerson} = require("path/to/module");
let person = await getPerson('some id');
const checkArrayForInteger = data => {
if(data.length < 1) return false;
let result = true;
data.forEach(num => {
if((num ^ 0) !== num) {
result = false;
return false;
}
});
return result;
};
const checkArrayForInteger = data => data.length > 1 ? _.every(data, num => _.isInteger(num)) : false;
navigator.geolocation.getCurrentPosition(
function(position) {
// success function
},
function(error) {
// error function
// Посмотреть какая ошибка
console.log(error);
});
PositionError("User denied Geolocation")
<form>
<p><input type="checkbox" data-name="chbx" value="first">first</p>
<p><input type="checkbox" data-name="chbx" value="second">second</p>
<p><input type="checkbox" data-name="chbx" value="third">third</p>
<p><input type="checkbox" data-name="chbx" value="fourth">fourth</p>
<p><input type="checkbox" data-name="chbx" value="fifth">fifth</p>
<input type="hidden" name="chbx">
<button onclick="myFilter()" class="sbtn">Подобрать</button>
</form>
function myFilter() {
var arr = [];
document.querySelectorAll("input[data-name='chbx']:checked").forEach(input => arr.push(input.value));
document.querySelector("input[name='chbx']").value = arr.join();
}