-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (36 loc) · 1.14 KB
/
index.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
$("#add_user").submit(function(event){
alert("Data Inserted Successfully!");
})
$("#update_user").submit(function(event){
event.preventDefault();
var unindexed_array = $(this).serializeArray();
var data = {}
$.map(unindexed_array, function(n, i){
data[n['name']] = n['value']
})
console.log(data);
var update_request = {
"url": `http://localhost:3000/api/users/${data.id}`,
"method": "PUT",
"data": data
}
$.ajax(update_request).done(function(response){
alert("Data Updated Successfully!");
})
})
if(window.location.pathname =="/"){
$ondelete = $(".table tbody td a.delete");
$ondelete.click(function(){
var id = $(this).attr("data-id")
var request = {
"url": `http://localhost:3000/api/users/${id}`,
"method": "DELETE"
}
if(confirm("Do you really want to delete this record?")){
$.ajax(request).done(function(response){
alert("Data Deleted Successfully!");
location.reload()
})
}
})
}