feat : fix fetch bug
This commit is contained in:
+5
-11
@@ -33,7 +33,7 @@
|
||||
|
||||
<div id="hasil_pencarian" class="mt-6 hidden p-4 rounded-xl border max-w-xl mx-auto text-left bg-white text-gray-800 shadow-lg transition-all">
|
||||
<p id="pesan_hasil" class="text-sm font-semibold"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -105,22 +105,17 @@
|
||||
|
||||
let map_marker = null;
|
||||
|
||||
// Fungsi baru untuk memuat statistik secara asinkron dari basis data
|
||||
async function muat_statistik_publik() {
|
||||
try {
|
||||
const respons_http = await fetch('http://localhost:3000/api/survey/statistik');
|
||||
// Diubah ke relative path
|
||||
const respons_http = await fetch('/api/survey/statistik');
|
||||
if (!respons_http.ok) throw new Error('Gagal mengambil data statistik');
|
||||
|
||||
const data_agregat = await respons_http.json();
|
||||
|
||||
// Memasukkan hasil hitungan ke dalam DOM menggunakan textContent
|
||||
document.getElementById('stat_publik_terverifikasi').textContent = data_agregat.terverifikasi || 0;
|
||||
document.getElementById('stat_publik_diproses').textContent = data_agregat.diproses || 0;
|
||||
|
||||
/* Baris Kompleks: Menggunakan objek bawaan Date pada JavaScript untuk
|
||||
mendapatkan waktu spesifik saat skrip ini berjalan di perangkat pengguna,
|
||||
lalu memformatnya secara spesifik ke dalam zona waktu WIB (Asia/Jakarta)
|
||||
agar seragam untuk seluruh pengunjung situs terlepas dari lokasi fisik perangkat mereka. */
|
||||
const objek_waktu_sekarang = new Date();
|
||||
const waktu_terformat_wib = objek_waktu_sekarang.toLocaleTimeString('id-ID', {
|
||||
hour: '2-digit',
|
||||
@@ -150,7 +145,8 @@
|
||||
tombol_cari.textContent = 'Mencari...';
|
||||
|
||||
try {
|
||||
const http_response = await fetch(`http://localhost:3000/api/survey/cek-nik/${input_nik_value}`);
|
||||
// Diubah ke relative path
|
||||
const http_response = await fetch(`/api/survey/cek-nik/${input_nik_value}`);
|
||||
|
||||
if (!http_response.ok) {
|
||||
throw new Error('Data tidak ditemukan');
|
||||
@@ -186,9 +182,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
// Mengeksekusi penarikan data statistik tepat saat halaman selesai dimuat
|
||||
muat_statistik_publik();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user