This commit is contained in:
2026-02-19 11:49:56 +01:00
parent c718f15f09
commit 581e726f78
2 changed files with 15 additions and 5 deletions

View File

@@ -145,10 +145,9 @@ class KIChat {
this.isTyping = true; this.isTyping = true;
try { try {
// Use relative path that works from any page location // Build absolute URL to ensure correct path on any hosting
const basePath = window.location.pathname.includes('/') ?
window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1) : '/';
const apiUrl = new URL('/scripts/add/send.php', window.location.origin).href; const apiUrl = new URL('/scripts/add/send.php', window.location.origin).href;
console.log('KI Chat: Sending to', apiUrl);
const response = await fetch(apiUrl, { const response = await fetch(apiUrl, {
method: 'POST', method: 'POST',
@@ -163,11 +162,14 @@ class KIChat {
}) })
}); });
console.log('KI Chat: Response status', response.status);
const data = await response.json(); 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); this.addMessage('ki', data.data.ai_response, data.data.timestamp);
} else { } else {
console.error('KI Chat: Invalid response structure', data);
this.addMessage('ki', 'Entschuldigung, es gab ein Problem. Bitte versuchen Sie es später erneut.'); this.addMessage('ki', 'Entschuldigung, es gab ein Problem. Bitte versuchen Sie es später erneut.');
} }
} catch (error) { } catch (error) {

View File

@@ -80,10 +80,15 @@ class DemoChat {
this.isTyping = true; this.isTyping = true;
try { 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', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify({
type: 'chat', type: 'chat',
@@ -92,11 +97,14 @@ class DemoChat {
}) })
}); });
console.log('Demo Chat: Response status', response.status);
const data = await response.json(); const data = await response.json();
console.log('Demo Chat: Response data', data);
if (data.success && data.data && data.data.ai_response) { if (data.success && data.data && data.data.ai_response) {
this.addMessageToUI('ki', data.data.ai_response); this.addMessageToUI('ki', data.data.ai_response);
} else { } else {
console.error('Demo Chat: Invalid response structure', data);
this.addMessageToUI('ki', 'Entschuldigung, es gab ein Problem. Bitte versuchen Sie es später erneut.'); this.addMessageToUI('ki', 'Entschuldigung, es gab ein Problem. Bitte versuchen Sie es später erneut.');
} }
} catch (error) { } catch (error) {