Add files via upload

This commit is contained in:
Tomáš Dvořák
2025-05-23 12:13:09 +02:00
committed by GitHub
parent f1263a1dca
commit 0348365b92
+21 -9
View File
@@ -552,21 +552,33 @@
try { try {
showMessage('Odesílání záznamu...', 'info'); showMessage('Odesílání záznamu...', 'info');
const res = await fetch('/submit', { const res = await fetch('/api/trips', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data), body: JSON.stringify(data),
}); });
const result = await res.json(); const text = await res.text();
showMessage(result.message, 'success');
// Reset form but keep today's date // Validate JSON response
form.reset(); try {
dateStart.value = todayStr; const result = JSON.parse(text);
dateEnd.value = todayStr; if (res.ok) {
totalDistance.textContent = '0 km'; showMessage(result.message || 'Záznam úspěšně uložen', 'success');
totalTime.textContent = '0:00';
// Reset form but keep today's date
form.reset();
dateStart.value = todayStr;
dateEnd.value = todayStr;
totalDistance.textContent = '0 km';
totalTime.textContent = '0:00';
} else {
showMessage(result.error || 'Chyba při ukládání', 'error');
}
} catch (jsonError) {
console.error('Invalid JSON response:', text);
showMessage('Neplatná odpověď ze serveru', 'error');
}
} catch (err) { } catch (err) {
console.error(err); console.error(err);
showMessage('Nepodařilo se odeslat záznam. Zkontrolujte připojení k internetu.', 'error'); showMessage('Nepodařilo se odeslat záznam. Zkontrolujte připojení k internetu.', 'error');