aboutsummaryrefslogtreecommitdiffstats
path: root/src/public/js/form.js
blob: 708542296943cd134f42bdbeda2c9533c6a7dc59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// File submit AJAX request
document.getElementById('upload').onsubmit = function () {
    let xhr = new XMLHttpRequest();
    xhr.open('POST', '/api/v1/upload');
    let formData = new FormData(this);
    xhr.send(formData);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            let response = JSON.parse(xhr.responseText);
            if (xhr.status === 200) {
                console.log(response);
            } else {
                console.log(response.error);
            }
        }
    };
    return false;
};