Skip to content

Commit 173907f

Browse files
frankslinclaude
andcommitted
修復驗證錯誤時前端仍嘗試請求 JSON 數據的問題
問題: 當用戶輸入無效的 ID(如 id=abc)時,雖然後端返回驗證錯誤頁面, 但前端 JavaScript 仍會自動調用 requestPersonData(),嘗試獲取 JSON 數據, 導致發出不必要的請求。 解決方案: 1. 在 Blade 模板中添加 hasValidationErrors 變量,指示是否存在驗證錯誤 2. 在頁面加載時檢查此變量,只有在沒有驗證錯誤時才調用 requestPersonData() 測試結果: - ✅ id=abc → 顯示錯誤,不發送 JSON 請求(hasValidationErrors = true) - ✅ id=1367 → 正常加載數據(hasValidationErrors = false) - ✅ id=0001367 → 正常加載數據(hasValidationErrors = false) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent da366df commit 173907f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

resources/views/cbdbapi/person.blade.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@
330330
var searchResultsData = @json($searchResults);
331331
var initialPersonIdData = @json($personId);
332332
var searchTermData = @json($searchTerm);
333+
var hasValidationErrors = @json(isset($validationErrors) && !empty($validationErrors));
333334
334335
(function () {
335336
var personId = '';
@@ -1011,7 +1012,11 @@ function loadPerson(newId) {
10111012
});
10121013
10131014
updateSearchResultHighlight();
1014-
requestPersonData();
1015+
1016+
// Only request person data if there are no validation errors
1017+
if (!hasValidationErrors) {
1018+
requestPersonData();
1019+
}
10151020
})();
10161021
</script>
10171022

0 commit comments

Comments
 (0)