From 2f4d9120958ac97501d2be37eb89b0c76e1f4560 Mon Sep 17 00:00:00 2001 From: frogymind Date: Tue, 10 Jun 2025 11:30:09 +0700 Subject: [PATCH] pertemuan 11 --- index.html | 28 ++++++++++++++++++++++++++++ js/carrack.js | 19 +++++++++++++++++++ js/data.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 index.html create mode 100644 js/carrack.js create mode 100644 js/data.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..f000894 --- /dev/null +++ b/index.html @@ -0,0 +1,28 @@ + + + + + + Widuri + + + + + + + + + + + + + + +
IDNamePhone
+ + + + + + + \ No newline at end of file diff --git a/js/carrack.js b/js/carrack.js new file mode 100644 index 0000000..db11e92 --- /dev/null +++ b/js/carrack.js @@ -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); +} diff --git a/js/data.js b/js/data.js new file mode 100644 index 0000000..429e97f --- /dev/null +++ b/js/data.js @@ -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; + }, + }, + ], +}) \ No newline at end of file