Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cc558ad78a |
@ -6,7 +6,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<input id="form-add-name" type="text" placeholder="Name" />
|
<input id="form-add-name" type="text" placeholder="Name" />
|
||||||
<input id="form-add-phone" type="text" placeholder="Phone" />
|
<input id="form-add-phone" type="text" placeholder="Phone" />
|
||||||
<button id="button-add" type="button" onclick="buttonAdd()">Create</button>
|
<button type="button" onclick="buttonAdd()">Create</button>
|
||||||
<hr>
|
<hr>
|
||||||
<table id="table-list">
|
<table id="table-list">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
35
js/data.js
35
js/data.js
@ -27,13 +27,13 @@ var table = $('#table-list').DataTable({
|
|||||||
{
|
{
|
||||||
"data": "name",
|
"data": "name",
|
||||||
"render": function(data, type, row) {
|
"render": function(data, type, row) {
|
||||||
return `<input id="form-edit-name-${row.id}" type="text" value="${data}">`;
|
return `<input id="form-edit-name-${row.id}" value="${data}">`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"data": "phone",
|
"data": "phone",
|
||||||
"render": function(data, type, row) {
|
"render": function(data, type, row) {
|
||||||
return `<input id="form-edit-phone-${row.id}" type="text" value="${data}">`;
|
return `<input id="form-edit-phone-${row.id}" value="${data}">`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -52,13 +52,10 @@ function buttonAdd() {
|
|||||||
var payload = {
|
var payload = {
|
||||||
"name":name,
|
"name":name,
|
||||||
"phone":phone
|
"phone":phone
|
||||||
};
|
|
||||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
|
||||||
if (error) console.error("Error:", error);
|
|
||||||
else {
|
|
||||||
table.ajax.reload(null, false); // false means keep the current page
|
|
||||||
console.log("JSON Response:", response);
|
|
||||||
}
|
}
|
||||||
|
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||||
|
if (error) console.error(`Error: ${error}`);
|
||||||
|
else table.ajax.reload(null, false);
|
||||||
}, "application/json");
|
}, "application/json");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,28 +67,22 @@ function buttonEdit(key){
|
|||||||
"key":key,
|
"key":key,
|
||||||
"name":name,
|
"name":name,
|
||||||
"phone":phone
|
"phone":phone
|
||||||
};
|
|
||||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
|
||||||
if (error) console.error("Error:", error);
|
|
||||||
else {
|
|
||||||
table.ajax.reload(null, false); // false means keep the current page
|
|
||||||
console.log("JSON Response:", response);
|
|
||||||
}
|
}
|
||||||
|
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||||
|
if (error) console.error(`Error: ${error}`);
|
||||||
|
else table.ajax.reload(null, false);
|
||||||
}, "application/json");
|
}, "application/json");
|
||||||
alert("Data telah di Update");
|
alert("Data berhasil dirubah");
|
||||||
}
|
}
|
||||||
|
|
||||||
function buttonRemove(key) {
|
function buttonRemove(key) {
|
||||||
var url = "http://localhost:11000/api/delete";
|
var url = "http://localhost:11000/api/delete";
|
||||||
var payload = {
|
var payload = {
|
||||||
"key":key
|
"key":key
|
||||||
};
|
}
|
||||||
sendHttpRequest(url, "POST", payload, function (error, response) {
|
sendHttpRequest(url, "POST", payload, function (error, response) {
|
||||||
if (error) console.error("Error:", error);
|
if (error) console.error(`Error: ${error}`);
|
||||||
else {
|
else table.ajax.reload(null, false);
|
||||||
table.ajax.reload(null, false); // false means keep the current page
|
|
||||||
console.log("JSON Response:", response);
|
|
||||||
}
|
|
||||||
}, "application/json");
|
}, "application/json");
|
||||||
alert("Data telah di Hapus Selamanya");
|
alert("Data berhasil dihapus, permanent, selamanya!");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user