location /admin {
root /home/web/domainname/public/admin;
index index.html;
try_files $uri $uri/ /index.html;
}
location / {
root /home/web/domainname/public/user;
index index.html;
try_files $uri $uri/ /index.html;
}
$(selector).on(...)
, то событие добавится на все элементы. Вам надо либо через document.querySelectorAll
это сделать, либо через делегирование событий. forEach
как раз ничего не изменяет. Он просто перебирает массив. const singleBusinessLogic = (function () {
const pending = [];
function finish(error, response) {
pending.forEach(callback => callback(error, response));
pending.length = 0;
}
return function (id, callback) {
if (pending.length === 0) {
fetch(`https://jsonplaceholder.typicode.com/users/${id}`)
.then(response => response.json())
.then(response => finish(null, response))
.catch(error => finish(error));
}
pending.push(callback);
};
})();
singleBusinessLogic(1, (error, data) => {
if (!error) {
console.log(data);
}
});
singleBusinessLogic(2, (error, data) => {
if (!error) {
console.log(data);
}
});
setTimeout(function () {
singleBusinessLogic(3, (error, data) => {
if (!error) {
console.log(data);
}
});
singleBusinessLogic(4, (error, data) => {
if (!error) {
console.log(data);
}
});
}, 1000);