-
Notifications
You must be signed in to change notification settings - Fork 0
/
homepage.js
56 lines (50 loc) · 1.75 KB
/
homepage.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
$(document).ready(function () {
$("form").submit(function (event) {
$(".form-group").removeClass("has-error");
$(".help-block").remove();
var formData = {
email: $("#email").val(),
password: $("#password").val(),
};
console.log(formData);
if (!validate(formData))
return;
else
$.ajax({
type: "POST",
url: "homepage.php",
data: formData,
dataType: "json",
encode: true,
})
.done(function (data) {
console.log(data);
if (data.admin) {
$("form").html('<script></script>' + '<div class="alert alert-success">' + data.message + "</div>");
window.location.href = 'AdminFirstPage.html';
}
if (data.customer) {
$("form").html('<script></script>' + '<div class="alert alert-success">' + data.message + "</div>");
window.location.href = 'Renting.php';
}
alert(data.message);
})
.fail(function (data) {
console.log("FAIL !")
// $("#message-group").html('<div class="alert alert-danger">Could not reach server, please try again later.</div>');
});
event.preventDefault();
});
});
function validate(formData) {
let valid = true;
if (formData["email"] === '') {
alert("Please Enter your Email");
valid = false;
}
if (formData["password"] === '') {
alert("Please Enter your Password");
valid = false;
}
return valid
}