Загрузка файла на сервер с помощью ajax
Реализуем загрузку файла на сервер с помощью ajax. Воспользуемся axios.
let formData = new FormData(),
input = document.getElementById('file');
//"file" - key on server
formData.append("file", input.files[0]);
// handler/path - your path
axios.post('/handler/path', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(res => {
console.log('success')
}).catch(e =>{
console.log('error')
})