1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
$("#avatarFile").on("change", () => {
var preview = document.querySelector('#image-preview');
var file = document.querySelector("#avatarFile").files[0];
var reader = new FileReader();
reader.addEventListener("load", () => {
preview.src = reader.result;
}, false);
if (file) {
reader.readAsDataURL(file);
}
});
$("#avatarForm").submit(function (e) {
var url = "/avatar";
var data = new FormData();
$.each(jQuery('#avatarFile')[0].files, (i, file) => {
data.append('avatar', file);
});
e.preventDefault();
$.ajax({
url: url,
data: data,
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
success: (data) => {
$("#avatarUploadSucceededAlert").show();
$("#avatarUploadSucceededMessage").text(data.success);
},
error: () => {
$("#avatarUploadFailedAlert").show();
}
});
});
|