From 581e726f78f9809292521aa7589843df1c478d0a Mon Sep 17 00:00:00 2001 From: Ihor_Zhekov Date: Thu, 19 Feb 2026 11:49:56 +0100 Subject: [PATCH] p --- Profice WebSite/scripts/chat.js | 10 ++++++---- Profice WebSite/scripts/demo-chat.js | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Profice WebSite/scripts/chat.js b/Profice WebSite/scripts/chat.js index 85d6261..f930779 100644 --- a/Profice WebSite/scripts/chat.js +++ b/Profice WebSite/scripts/chat.js @@ -145,10 +145,9 @@ class KIChat { this.isTyping = true; try { - // Use relative path that works from any page location - const basePath = window.location.pathname.includes('/') ? - window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1) : '/'; + // Build absolute URL to ensure correct path on any hosting const apiUrl = new URL('/scripts/add/send.php', window.location.origin).href; + console.log('KI Chat: Sending to', apiUrl); const response = await fetch(apiUrl, { method: 'POST', @@ -163,11 +162,14 @@ class KIChat { }) }); + console.log('KI Chat: Response status', response.status); const data = await response.json(); + console.log('KI Chat: Response data', data); - if (data.success) { + if (data.success && data.data && data.data.ai_response) { this.addMessage('ki', data.data.ai_response, data.data.timestamp); } else { + console.error('KI Chat: Invalid response structure', data); this.addMessage('ki', 'Entschuldigung, es gab ein Problem. Bitte versuchen Sie es später erneut.'); } } catch (error) { diff --git a/Profice WebSite/scripts/demo-chat.js b/Profice WebSite/scripts/demo-chat.js index 8a635ee..9d8a566 100644 --- a/Profice WebSite/scripts/demo-chat.js +++ b/Profice WebSite/scripts/demo-chat.js @@ -80,10 +80,15 @@ class DemoChat { this.isTyping = true; try { - const response = await fetch('/scripts/add/send.php', { + // Build absolute URL to ensure correct path on any hosting + const apiUrl = new URL('/scripts/add/send.php', window.location.origin).href; + console.log('Demo Chat: Sending to', apiUrl); + + const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', + 'Accept': 'application/json' }, body: JSON.stringify({ type: 'chat', @@ -92,11 +97,14 @@ class DemoChat { }) }); + console.log('Demo Chat: Response status', response.status); const data = await response.json(); + console.log('Demo Chat: Response data', data); if (data.success && data.data && data.data.ai_response) { this.addMessageToUI('ki', data.data.ai_response); } else { + console.error('Demo Chat: Invalid response structure', data); this.addMessageToUI('ki', 'Entschuldigung, es gab ein Problem. Bitte versuchen Sie es später erneut.'); } } catch (error) {