Compare commits

..

1 Commits
pagi ... master

Author SHA1 Message Date
cc558ad78a CRUD selesai 2025-06-17 16:11:09 +07:00
2 changed files with 32 additions and 41 deletions

View File

@ -6,7 +6,7 @@
<body>
<input id="form-add-name" type="text" placeholder="Name" />
<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>
<table id="table-list">
<thead>

View File

@ -27,13 +27,13 @@ var table = $('#table-list').DataTable({
{
"data": "name",
"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",
"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}">`;
}
},
{
@ -46,52 +46,43 @@ var table = $('#table-list').DataTable({
})
function buttonAdd() {
var name = document.getElementById("form-add-name" ).value;
var phone = document.getElementById("form-add-phone" ).value;
var url = "http://localhost:11000/api/create";
var payload = {
"name" : name,
"phone" : phone
};
var name = document.getElementById("form-add-name").value;
var phone = document.getElementById("form-add-phone").value;
var url = "http://localhost:11000/api/create";
var payload = {
"name":name,
"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);
}
if (error) console.error(`Error: ${error}`);
else table.ajax.reload(null, false);
}, "application/json");
}
function buttonEdit(key){
var name = document.getElementById(`form-edit-name-${key}` ).value;
var phone = document.getElementById(`form-edit-phone-${key}` ).value;
var url = "http://localhost:11000/api/update";
var payload = {
"key" : key,
"name" : name,
"phone" : phone
};
function buttonEdit(key) {
var name = document.getElementById(`form-edit-name-${key}`).value;
var phone = document.getElementById(`form-edit-phone-${key}`).value;
var url = "http://localhost:11000/api/update";
var payload = {
"key":key,
"name":name,
"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);
}
if (error) console.error(`Error: ${error}`);
else table.ajax.reload(null, false);
}, "application/json");
alert("Data telah di Update");
alert("Data berhasil dirubah");
}
function buttonRemove(key){
var url = "http://localhost:11000/api/delete";
var payload = {
"key" : key
};
function buttonRemove(key) {
var url = "http://localhost:11000/api/delete";
var payload = {
"key":key
}
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);
}
if (error) console.error(`Error: ${error}`);
else table.ajax.reload(null, false);
}, "application/json");
alert("Data telah di Hapus Selamanya");
alert("Data berhasil dihapus, permanent, selamanya!");
}