pertemuan 11
This commit is contained in:
commit
2f4d912095
28
index.html
Normal file
28
index.html
Normal file
@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Widuri</title>
|
||||
<link rel="stylesheet" href="//cdn.datatables.net/2.3.2/css/dataTables\.dataTables.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<table id="table-list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Phone</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody></tbody>
|
||||
|
||||
</table>
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
||||
<script src="//cdn.datatables.net/2.3.2/js/dataTables.min.js"></script>
|
||||
|
||||
<script src="js/carrack.js"></script>
|
||||
<script src="js/data.js"></script>
|
||||
</body>
|
||||
</html>
|
19
js/carrack.js
Normal file
19
js/carrack.js
Normal file
@ -0,0 +1,19 @@
|
||||
function sendHttpRequest(url, method, data, callback, contentType = "multipart/form-data", authorization = "") {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open(method, url, true);
|
||||
xhr.setRequestHeader("Content-Type", contentType);
|
||||
xhr.setRequestHeader("Authorization", authorization);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
var response = xhr.responseText;
|
||||
callback(null, response);
|
||||
}
|
||||
else callback(xhr.status, null);
|
||||
}
|
||||
};
|
||||
var requestData;
|
||||
if (contentType === "application/json") requestData = JSON.stringify(data);
|
||||
else requestData = data;
|
||||
xhr.send(requestData);
|
||||
}
|
35
js/data.js
Normal file
35
js/data.js
Normal file
@ -0,0 +1,35 @@
|
||||
var table = $('#table-list').DataTable({
|
||||
"ajax": {
|
||||
"url": "http://localhost:11000/api/read",
|
||||
"type": "POST",
|
||||
"dataSrc": "data",
|
||||
"contentType": "application/json",
|
||||
"data": function (d) {
|
||||
return JSON.stringify({});
|
||||
},
|
||||
"error": function (xhr, error, thrown) {
|
||||
console.error("Error fetching data:", thrown);
|
||||
console.error("Response:", xhr.responseText);
|
||||
}
|
||||
},
|
||||
"columns": [
|
||||
{
|
||||
"data": "id",
|
||||
"render": function (data, type, row) {
|
||||
return data;
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": "name",
|
||||
"render": function (data, type, row) {
|
||||
return data;
|
||||
},
|
||||
},
|
||||
{
|
||||
"data": "phone",
|
||||
"render": function (data, type, row) {
|
||||
return data;
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
Loading…
Reference in New Issue
Block a user