Uploading file using ajax
Let's upload a file to the server using ajax. Let's use 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')
})