diff --git a/backend/app/Core/Response.php b/backend/app/Core/Response.php index 58c2af7..688d4a3 100644 --- a/backend/app/Core/Response.php +++ b/backend/app/Core/Response.php @@ -54,7 +54,11 @@ class Response $this->sendHeaders(); http_response_code($this->statusCode); - echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + if (ob_get_length()) { + ob_clean(); + } + + echo json_encode($data, JSON_UNESCAPED_UNICODE); exit; } diff --git a/backend/app/Views/TeacherPortal.php b/backend/app/Views/TeacherPortal.php index b7eb3da..d37b356 100644 --- a/backend/app/Views/TeacherPortal.php +++ b/backend/app/Views/TeacherPortal.php @@ -668,21 +668,33 @@ class TeacherPortal const res = await fetch('/api/chat/conversations', { headers: { 'Authorization': 'Bearer ' + token } }); - const data = await res.json(); + const text = await res.text(); + let data; + try { + data = JSON.parse(text); + } catch (jsonErr) { + console.error('Conversations parse error:', jsonErr, 'Raw:', text); + const container = document.getElementById('conv_list_container'); + if (container) { + container.innerHTML = '
خطأ في معالجة البيانات
'; + } + return; + } + if (res.ok && data.status === 'success') { - renderConversations(data.data); + renderConversations(data.data || []); } else { - console.warn('Load convs returned:', data); + console.warn('Load convs returned error payload:', data); const container = document.getElementById('conv_list_container'); if (container) { container.innerHTML = '
' + (data.message || 'لا توجد محادثات نشطة') + '
'; } } } catch (e) { - console.error('Load convs error:', e); + console.error('Load convs network error:', e); const container = document.getElementById('conv_list_container'); if (container) { - container.innerHTML = '
تعذر تحميل المحادثات (خطأ في الاتصال)
'; + container.innerHTML = '
تعذر تحميل المحادثات
'; } } }