-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (47 loc) · 1.67 KB
/
app.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
$(document).ready(function() {
const registrationForm = $("#registrationForm");
const successMessage = $("#successMessage");
const errorMessage = $("#errorMessage");
const userTable = $("#userTable tbody");
registrationForm.submit(function(event) {
event.preventDefault();
const formData = registrationForm.serialize();
$.ajax({
type: "POST",
url: "register.php",
data: formData,
dataType: "json",
success: function(response) {
if (response.success) {
successMessage.text(response.message).show();
registrationForm.hide();
errorMessage.hide();
getUserList();
} else {
errorMessage.text(response.message).show();
successMessage.hide();
}
},
error: function(error) {
console.error("Помилка: " + JSON.stringify(error));
}
});
});
function getUserList() {
$.ajax({
type: "GET",
url: "getUsers.php",
dataType: "json",
success: function(users) {
userTable.empty();
$.each(users, function(index, user) {
userTable.append(`<tr><td>${user.id}</td><td>${user.firstName}</td><td>${user.lastName}</td><td>${user.email}</td><td>${user.password}</td></tr>`);
});
},
error: function(error) {
console.error("Помилка: " + JSON.stringify(error));
}
});
}
getUserList();
});