From 686e395fcd4bc117459f0955fa3588cfb76ef1b9 Mon Sep 17 00:00:00 2001 From: Aleeeehh Date: Sat, 2 Aug 2025 01:48:18 +0200 Subject: [PATCH] add another test POST api --- testing/index.html | 8 ++++++++ testing/script.js | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/testing/index.html b/testing/index.html index 45c5ef9..5c37f3c 100644 --- a/testing/index.html +++ b/testing/index.html @@ -51,6 +51,13 @@ .btn-post:hover { background-color: #1976D2; } + .btn-coordinates { + background-color: #FF9800; + color: white; + } + .btn-coordinates:hover { + background-color: #F57C00; + } .result { background-color: #f9f9f9; border: 1px solid #ddd; @@ -86,6 +93,7 @@
+
diff --git a/testing/script.js b/testing/script.js index 49816d4..0b2f3f3 100644 --- a/testing/script.js +++ b/testing/script.js @@ -1,4 +1,4 @@ -const API_BASE_URL = 'http://localhost:8000'; +const API_BASE_URL = 'https://fbbb261497e3.ngrok-free.app'; // Funzione per mostrare messaggi di status function showStatus(message, isSuccess = true) { @@ -61,6 +61,38 @@ async function createData() { } } +// POST: Inserisce coordinate nel database +async function createCoordinates() { + try { + console.log('📍 Richiesta POST coordinate in corso...'); + showStatus('📍 Richiesta POST coordinate in corso...', true); + + coordinates = { + "coords": [123.12,456.78], + } + + const response = await fetch(`${API_BASE_URL}/geo-access`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(coordinates) + }); + + const data = await response.json(); + + if (response.ok) { + showStatus('✅ Coordinate inserite con successo!', true); + showResult(data); + } else { + showStatus(`❌ Errore: ${data.detail || 'Errore sconosciuto'}`, false); + } + } catch (error) { + console.error('Errore POST coordinate:', error); + showStatus(`❌ Errore di connessione: ${error.message}`, false); + } +} + // Test di connessione all'avvio window.addEventListener('load', async () => { try {