konversi-lokasi.php
unknown
plain_text
a year ago
3.1 kB
8
Indexable
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Update ID Kelurahan</title> <style> body { font-family: Arial, sans-serif; margin: 20px; } #form-container { max-width: 500px; margin: 0 auto; } input[type="number"], input[type="submit"] { width: 100%; padding: 10px; margin-bottom: 10px; box-sizing: border-box; } #log { margin-top: 20px; } </style> </head> <body> <div id="form-container"> <h2>Update ID Kelurahan</h2> <form id="updateForm"> <label for="rowCount">Jumlah Baris:</label> <input type="number" id="rowCount" name="rowCount" min="1" required> <input type="submit" value="Proses"> </form> </div> <div id="log"></div> <script> document.getElementById('updateForm').addEventListener('submit', function(event) { event.preventDefault(); const rowCount = document.getElementById('rowCount').value; if (!rowCount) { alert('Masukkan jumlah baris.'); return; } fetch(`get_rows.php?rowCount=${rowCount}`) .then(response => response.json()) .then(data => { data.forEach(row => { const { Lat, Longitude } = row; // Corrected the variable names fetch(`proxy.php?latitude=${Lat}&longitude=${Longitude}`) // Updated variable names .then(response => response.json()) .then(data => { const kelurahanId = data.id_desa_terdekat; // Corrected the property name document.getElementById('log').innerHTML += `Berhasil (${kelurahanId}) - Lat(${Lat}) & Lon(${Longitude})<br>`; // Updated variable names updateKelurahanId(kelurahanId, Lat, Longitude); // Updated variable names }) .catch(error => { console.error('Error:', error); document.getElementById('log').innerHTML += `Gagal mendapatkan ID kelurahan - Lat(${Lat}) & Lon(${Longitude})<br>`; // Updated variable names }); }); }) .catch(error => { console.error('Error:', error); document.getElementById('log').innerHTML = 'Gagal mendapatkan data baris.'; }); }); function updateKelurahanId(kelurahanId, latitude, longitude) { // Menggunakan fetch untuk melakukan update ke server // Ganti URL dan method sesuai dengan kebutuhan fetch('update_kelurahan.php', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ kelurahanId: kelurahanId, latitude: latitude, longitude: longitude }), }) .then(response => response.json()) .then(data => console.log('Update berhasil:', data)) .catch(error => console.error('Error:', error)); } </script> </body> </html>
Editor is loading...
Leave a Comment