handleSubmit vollständige URL mit Host und dem aktuellen Pfad (pathname)

This commit is contained in:
ISA
2024-11-09 12:23:12 +01:00
parent c329ab90fc
commit 675843b3b3

View File

@@ -137,30 +137,40 @@ function SettingModal({ showModal, onClose }) {
// Falls Änderungen vorhanden sind, sende die neuen Daten
if (Object.keys(changes).length > 0) {
let url = `CPL?${currentPath}`;
// Get the current path and ensure it ends with ".html"
let currentPath = window.location.pathname;
if (!currentPath.endsWith(".html")) {
currentPath += ".html";
}
// Full URL with host, current path, and all change parameters
let url = `${window.location.origin}/CPL?${currentPath}`;
Object.keys(changes).forEach((paramKey) => {
url += `&${paramKey}=${encodeURIComponent(changes[paramKey])}`;
});
// Log the full URL to the console for debugging
console.log(url);
// Send the URL with changes to the server
fetch(url, { method: "GET" })
.then((response) => {
if (response.ok) {
alert("Daten erfolgreich gesendet!");
} else {
alert("Daten erfolgreich gesendet!");
//alert("Fehler beim Senden der Daten!"); weil wird sofort ausgefüht und bekommt kein Antwort
alert("Fehler beim Senden der Daten!");
}
})
.catch((error) => {
console.error("Fehler:", error);
//alert("Fehler beim Senden der Daten!"); weil wird sofort ausgefüht und bekommt kein Antwort
alert("Daten erfolgreich gesendet!");
alert("Fehler beim Senden der Daten!");
});
} else {
alert("Keine Änderungen vorgenommen.");
}
};
const handleSetDateTime = () => {
const currentDate = new Date();