-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_user_data.js
58 lines (52 loc) · 1.79 KB
/
get_user_data.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
document.addEventListener('DOMContentLoaded', function () {
let elems = document.querySelectorAll('.datepicker');
let instances = M.Datepicker.init(elems, {
"format": "dd-mm-yyyy"
});
});
let userEmail = getCookie('email');
console.log(userEmail);
ajax('core/get_user_data.php', 'POST', getUserData, { "email": userEmail });
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function getUserData(result) {
result = JSON.parse(result);
console.log(result);
document.querySelector('#signup-name').value = result.name;
document.querySelector('#signup-pass').value = result.password;
document.querySelector('#signup-birthday').value = result.birthday;
M.updateTextFields();
}
document.querySelector('#signup-submit').onclick = function (event) {
event.preventDefault();
M.updateTextFields();
let updateData = {
"email": userEmail,
"name": document.querySelector('#signup-name').value,
"pass": document.querySelector('#signup-pass').value,
"birthday": document.querySelector('#signup-birthday').value,
};
ajax('core/update_user_data.php', 'POST', updateUserData, updateData);
}
function updateUserData(result) {
console.log(result);
if (result == 1) {
alert('Данные успешно обновлены!');
}
else {
alert('ошибка обновления');
}
}