mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-05 04:52:58 +00:00
Add files via upload
This commit is contained in:
+15
-3
@@ -552,14 +552,19 @@
|
|||||||
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');
|
|
||||||
|
// Validate JSON response
|
||||||
|
try {
|
||||||
|
const result = JSON.parse(text);
|
||||||
|
if (res.ok) {
|
||||||
|
showMessage(result.message || 'Záznam úspěšně uložen', 'success');
|
||||||
|
|
||||||
// Reset form but keep today's date
|
// Reset form but keep today's date
|
||||||
form.reset();
|
form.reset();
|
||||||
@@ -567,6 +572,13 @@
|
|||||||
dateEnd.value = todayStr;
|
dateEnd.value = todayStr;
|
||||||
totalDistance.textContent = '0 km';
|
totalDistance.textContent = '0 km';
|
||||||
totalTime.textContent = '0:00';
|
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');
|
||||||
|
|||||||
Reference in New Issue
Block a user