aboutsummaryrefslogtreecommitdiffstats
path: root/src/public/js/form.js
blob: cfa80fd54d162f1e4738182acdee51363bc8b456 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
document.getElementById('upload').onsubmit = function () {
    var data = new FormData(document.getElementById('upload'));
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/api/upload');
    xhr.send(data);
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var response = JSON.parse(xhr.responseText);
            if (response.success) {
                document.getElementById('success').style.display = 'block';
            } else {
                document.getElementById('error').style.display = 'block';
            }
        }
    };
    return false;
};