forked from Adleraci/adlerka.top
Add file upload
This commit is contained in:
@@ -537,4 +537,24 @@ if ("loading" === document.readyState) {
|
||||
document.addEventListener("DOMContentLoaded", initAjax);
|
||||
} else {
|
||||
setTimeout(initAjax, 0);
|
||||
}
|
||||
|
||||
function uploadFile() {
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
const file = fileInput.files[0];
|
||||
let formData = new FormData();
|
||||
formData.append('userfile', file);
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '__URL__', true);
|
||||
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
document.getElementById('uploadStatus').innerHTML = 'File uploaded successfully.';
|
||||
} else {
|
||||
document.getElementById('uploadStatus').innerHTML = 'Error uploading file.';
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
}
|
Reference in New Issue
Block a user