JSFiddle - React, Tailwind, and code Playground
JavaScript
form.onsubmit = function(event) {
event.preventDefault();
// Update button text.
uploadButton.innerHTML = 'Uploading...';
var files = fileSelect.files;
var formData = new FormData();
for (var i = 0; i < files.length; i++) {
var file = files[i];
// Check the file type.
if (!file.type.match('image.*')) {
continue;
}
// Add the file to the request.
formData.append('file[]', finalFiles, file.name);
}
// Files
formData.append(name, finalFiles, filename);
// Set up the request.
console.log(file);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://zayavlenie.com.ua/mail-dev.php', true);
// The rest of the code will go here...
// Set up a handler for when the request finishes.
xhr.onload = function() {
if (xhr.status === 200) {
// File(s) uploaded.
uploadButton.innerHTML = 'Отправка';
} else {
alert('An error occurred!');
}
};
xhr.send(formData);
}