Лучшее на RU-vid
Кино
Авто/Мото
Видеоклипы
Животные
Спорт
Игры
Приколы
Развлечения
Хобби
Наука
Авторизоваться
Зарегистрироваться
No video :(
dynamic file upload progress Vanilla JS
`Orange.io`
Подписаться 192
Просмотров 13
50%
1
Видео
Поделиться
Скачать
Добавить в
Опубликовано:
6 сен 2024
Поделиться:
Ссылка:
Скачать:
Готовим ссылку...
Добавить в:
Мой плейлист
Посмотреть позже
Комментарии :
1
@OfficialOrangeio
2 месяца назад
/* usage: make sure to change action="your_url/post" Upload a file 0% */ const fileInput = document.getElementById('file'); const uploadBtn = document.getElementById('upload-btn'); const progressBar = document.getElementById('progress-bar'); const progressLabel = document.getElementById('progress-label'); const form = document.getElementById('upload-form'); uploadBtn.addEventListener('click', () => { const file = fileInput.files[0]; if (!file) return alert("Please select a file."); const payload = new FormData(); payload.append('user-image', file); fetchWithProgress(form.action, payload, percentComplete => { progressBar.value = percentComplete; progressLabel.textContent = `${Math.round(percentComplete)}%`; }).then(response => { if (response.ok) return response.json(); throw new Error(response.statusText); }).then(data => console.log(data)) .catch(error => console.error('Error:', error)); }); const fetchWithProgress = (url, body, onProgress) => new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open('POST', url); xhr.upload.onprogress = event => { if (event.lengthComputable) onProgress((event.loaded / event.total) * 100); }; xhr.onload = () => (xhr.status >= 200 && xhr.status < 300) ? resolve({ ok: true, status: xhr.status, statusText: xhr.statusText, json: () => JSON.parse(xhr.responseText) }) : reject({ status: xhr.status, statusText: xhr.statusText }); xhr.onerror = () => reject({ status: xhr.status, statusText: xhr.statusText }); xhr.send(body); });
Далее
7:19
Brutally honest advice for new .NET Web Developers
Просмотров 170 тыс.
28:09
Black Students Get WAKE UP CALL On Reality Of White Americans & White Privilege
Просмотров 424 тыс.
00:56
Друг без машины #непосредственнокаха
Просмотров 2,5 млн
00:16
Fake watermelon by Secret Vlog
Просмотров 3,1 млн
00:10
What does Satoru Gojo have? #cosplay#joker#Harley Quinn
Просмотров 3,1 млн
01:00
Нарвался на сотрудника ФСБ⚡️
Просмотров 75 тыс.
8:10
Fiber Optic - 2 Cables One APC E2000 Wall Box
Просмотров 4
14:43
Should you use Ruby on Rails in 2024?
Просмотров 48 тыс.
10:21
Adobe: A Disgusting, Criminal Company
Просмотров 353 тыс.
22:50
Multi-Level Navbar Menu in Power Apps
Просмотров 875
18:07
My DREAM Everyday Tech!
Просмотров 4,4 млн
10:17
I Quit Netflix and Use These FREE Alternatives Instead
Просмотров 404 тыс.
12:33
13 Things To Remove From Your Website Immediately
Просмотров 312 тыс.
9:38
5 JavaScript Concepts You HAVE TO KNOW
Просмотров 1,4 млн
48:48
20 Emerging Technologies That Will Change The World
Просмотров 1,3 млн
2:02
Transfer File Android to PC using Termux Netcat
Просмотров 17
00:56
Друг без машины #непосредственнокаха
Просмотров 2,5 млн