-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajax_login.js
38 lines (37 loc) · 1.24 KB
/
ajax_login.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
$(document).ready(function() {
$("form").submit(function(event) {
event.preventDefault();
var username = $("#username_").val();
var password = $("#password_").val();
var submit = $("#submit-but").val();
$.ajax({
type: 'POST',
url: "login.php",
data: {
username: username,
password: password,
submit: submit,
},
dataType: 'json',
success: function(data) {
if(data[0] == false && data[1] == false) {
if(username == 'admin') {
window.location = "adminDashboardPage.php";
}
else {
window.location = "userDashboard.php";
}
}
if(data[0] == true) {
$("#username_").addClass("input-error");
}
if(data[1] == true) {
$("#password_").addClass("input-error");
}
if(data[0] == true && data[1] == true) {
alert("No such account exist!");
}
}
});
});
});