Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52afee5e25 | |||
| 7c00802a77 |
@ -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 type="button" onclick="buttonAdd()">Create</button>
|
<button id="button-add" type="button" onclick="buttonAdd()">Create</button>
|
||||||
<hr>
|
<hr>
|
||||||
<table id="table-list">
|
<table id="table-list">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
71
js/data.js
71
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}" value="${data}">`;
|
return `<input id="form-edit-name-${row.id}" type="text" value="${data}">`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"data": "phone",
|
"data": "phone",
|
||||||
"render": function(data, type, row) {
|
"render": function(data, type, row) {
|
||||||
return `<input id="form-edit-phone-${row.id}" value="${data}">`;
|
return `<input id="form-edit-phone-${row.id}" type="text" value="${data}">`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -46,43 +46,52 @@ var table = $('#table-list').DataTable({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function buttonAdd() {
|
function buttonAdd() {
|
||||||
var name = document.getElementById("form-add-name").value;
|
var name = document.getElementById("form-add-name" ).value;
|
||||||
var phone = document.getElementById("form-add-phone").value;
|
var phone = document.getElementById("form-add-phone" ).value;
|
||||||
var url = "http://localhost:11000/api/create";
|
var url = "http://localhost:11000/api/create";
|
||||||
var payload = {
|
var payload = {
|
||||||
"name":name,
|
"name" : name,
|
||||||
"phone":phone
|
"phone" : phone
|
||||||
}
|
};
|
||||||
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 table.ajax.reload(null, false);
|
else {
|
||||||
|
table.ajax.reload(null, false); // false means keep the current page
|
||||||
|
console.log("JSON Response:", response);
|
||||||
|
}
|
||||||
}, "application/json");
|
}, "application/json");
|
||||||
}
|
}
|
||||||
|
|
||||||
function buttonEdit(key) {
|
function buttonEdit(key){
|
||||||
var name = document.getElementById(`form-edit-name-${key}`).value;
|
var name = document.getElementById(`form-edit-name-${key}` ).value;
|
||||||
var phone = document.getElementById(`form-edit-phone-${key}`).value;
|
var phone = document.getElementById(`form-edit-phone-${key}` ).value;
|
||||||
var url = "http://localhost:11000/api/update";
|
var url = "http://localhost:11000/api/update";
|
||||||
var payload = {
|
var payload = {
|
||||||
"key":key,
|
"key" : key,
|
||||||
"name":name,
|
"name" : name,
|
||||||
"phone":phone
|
"phone" : phone
|
||||||
}
|
};
|
||||||
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 table.ajax.reload(null, false);
|
else {
|
||||||
|
table.ajax.reload(null, false); // false means keep the current page
|
||||||
|
console.log("JSON Response:", response);
|
||||||
|
}
|
||||||
}, "application/json");
|
}, "application/json");
|
||||||
alert("Data berhasil dirubah");
|
alert("Data telah di Update");
|
||||||
}
|
}
|
||||||
|
|
||||||
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 table.ajax.reload(null, false);
|
else {
|
||||||
|
table.ajax.reload(null, false); // false means keep the current page
|
||||||
|
console.log("JSON Response:", response);
|
||||||
|
}
|
||||||
}, "application/json");
|
}, "application/json");
|
||||||
alert("Data berhasil dihapus, permanent, selamanya!");
|
alert("Data telah di Hapus Selamanya");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user