pertemuan 11 ketinggalan

This commit is contained in:
Naufal 2025-06-10 11:36:16 +07:00
parent 0643a5596e
commit ae37af408e
2 changed files with 54 additions and 0 deletions

19
js/carrack.js Normal file
View 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
View File

@ -0,0 +1,35 @@
var table = $('#table-list').DataTable({
"ajax": {
"url": "http://localhost:11000/api/read",
"tyoe": "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("Respones", 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;
}
},
]
})