pertemuan 11 ketinggalan
This commit is contained in:
parent
0643a5596e
commit
ae37af408e
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",
|
||||||
|
"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;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user