-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
114 lines (100 loc) · 3.25 KB
/
code.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// onload of page get all data
//window.onload = getAllData;
$("#addData-form").submit(function (event)
{
var name = $("#name").val();
var price = $("#price").val();
if (name == "" || price == "")
{
alertify.error("Fill all Input Feilds");
}
else
{
let formdata = new FormData();
formdata.append("name", name);
formdata.append("price", price);
let loca = "classes/components/userComponents.php?dataPurpose=addData";
fetch(loca, { method: "POST", body: formdata })
.then((res) => res.json())
.then((data) => {
console.log(data);
var result = (data);
if (result.response == true)
{
alertify.success(result.message);
}
else
{
alertify.set({ delay: 15000 });
alertify.error(result.message);
}
});
}
getAllData();
event.preventDefault();
});
function getAllData()
{
let formdata = new FormData();
formdata.append("getData", '1')
fetch("classes/components/userComponents.php?dataPurpose=getAllData", {
method: "POST",
body: formdata,
})
.then(res => res.json())
.then(data => {
console.log(data)
//adds the data the table
document.getElementById("showdata").innerHTML = data;
});
}
function editData(pid)
{
var name = $("#name").val();
var price = $("#price").val();
let formdata = new FormData();
formdata.append("name", name)
formdata.append("price", price)
formdata.append("pid", pid)
fetch("classes/components/userComponents.php?dataPurpose=editData", {
method: "POST",
body: formdata,
})
.then(res => res.json())
.then(data => {
console.log(data)
var result = (data);
if (result.response == true)
{
alertify.success(result.message);
}
else
{
alertify.set({ delay: 15000 });
alertify.error(result.message);
}
});
}
function deleteData(pid)
{
let formdata = new FormData();
formdata.append("pid", pid)
fetch("classes/components/userComponents.php?dataPurpose=deleteData", {
method: "POST",
body: formdata,
})
.then(res => res.json())
.then(data => {
console.log(data)
var result = (data);
if (result.response == true)
{
alertify.success(result.message);
}
else
{
alertify.set({ delay: 15000 });
alertify.error(result.message);
}
});
}