document.addEventListener('DOMContentLoaded', () => { // Charger les valeurs actuelles fetch('conf.json') .then(r => r.json()) .then(conf => { for (const key in conf) { const el = document.getElementById(key.toLowerCase()); if (el) el.value = conf[key]; } }); // Sauvegarder à l'appui sur VALIDER document.getElementById('validate').onclick = function() { const data = {}; ['ssid','password','kp','ki','kd'].forEach(key => { const el = document.getElementById(key); if (el) data[key] = el.value; }); fetch('/save_config', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data) }).then(r => { if (r.ok) alert('Configuration enregistrée !'); else alert('Erreur lors de l\'enregistrement'); }); }; }); fetch('conf.json') .then(r => r.json()) .then(conf => { for (const key in conf) { const el = document.getElementById(key); if (el) el.value = conf[key]; } });