-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.js
100 lines (66 loc) · 1.84 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// get users
let uri="http://localhost:8080/user/login"
$( document ).ready(function() {
console.log( "ready!" );
$(".btn-cl").on('click', function(){
$("#update-user").modal('hide');
$("#add-user").modal('hide');
})
$("#edit-state-button").on('click', function(){
editState()
})
$("#btn-addone").on('click', function(){
$("#add-user").modal('show');
})
$("#login").on('click', function(){
login()
})
});
// add State
function login(){
let name=$("#username").val()
if (name !== "") {
let oneuser ={
username:$("#username").val(),
password:$("#password").val(),
}
$.ajax({
url: uri,
type: 'POST',
contentType :'application/json',
data: JSON.stringify(oneuser),
success: function (data ) {
localStorage.setItem("username",oneuser.username);
window.location.href = "index.html";
// window.location.reload()
},
error: function (request , msg , error) {
alert('Can not post');
}
});
}else{
alert("no value given")
}
}
function deleteuser(id){
if (confirm("are you sure you want to delete this user") == true) {
deletethisuser(id)
} else {
}
}
function deletethisuser(id){
$.ajax({
url: uri+`${id}`,
type: 'DELETE',
success: function (data ) {
console.log("Suuceccfully deleted");
// console.log(data);
//window.location.reload()
GetStates();
},
error: function (request , msg , error) {
console.log('Can not post');
GetStates();
}
});
}