diff --git a/resources/views/chat/partials/user-actions.blade.php b/resources/views/chat/partials/user-actions.blade.php index b5ba871..8ec48eb 100644 --- a/resources/views/chat/partials/user-actions.blade.php +++ b/resources/views/chat/partials/user-actions.blade.php @@ -93,7 +93,20 @@ /** 获取用户资料 */ async fetchUser(username) { try { - const res = await fetch('/user/' + encodeURIComponent(username)); + const res = await fetch('/user/' + encodeURIComponent(username), { + headers: { + 'Accept': 'application/json', + 'X-Requested-With': 'XMLHttpRequest' + } + }); + + if (!res.ok) { + const errorData = await res.json().catch(() => ({})); + console.error('Failed to fetch user:', errorData.message || res.statusText); + // 如果是 404 或者 500 等错误,直接静默退出或提示 + return; + } + const data = await res.json(); if (data.status === 'success') { this.userInfo = data.data; @@ -103,7 +116,7 @@ this.whisperList = []; } } catch (e) { - console.error(e); + console.error('Error fetching user:', e); } }, @@ -333,7 +346,8 @@