Bikin form Add
This commit is contained in:
parent
65f4657d4d
commit
7c00802a77
@ -4,9 +4,9 @@
|
||||
<link rel="stylesheet" href="//cdn.datatables.net/2.3.2/css/dataTables.dataTables.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<input type="text" placeholder="Name" />
|
||||
<input type="text" placeholder="Phone" />
|
||||
<button>Create</button>
|
||||
<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>
|
||||
<hr>
|
||||
<table id="table-list">
|
||||
<thead>
|
||||
|
18
js/data.js
18
js/data.js
@ -40,3 +40,21 @@ 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
|
||||
};
|
||||
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);
|
||||
}
|
||||
}, "application/json");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user