fix: 修复设置页 AI API 测试功能的错误处理

- 改进错误消息的显示逻辑,正确处理 wp_send_json_error 返回的数据
- 添加更详细的 AJAX 错误日志输出
- 添加测试脚本 test-api-test-function.php 用于诊断 API 测试功能
This commit is contained in:
2026-01-26 13:52:26 +08:00
parent 7af137ae91
commit cedd977673
2 changed files with 170 additions and 2 deletions

View File

@@ -2454,10 +2454,14 @@ function themeoptions_page(){
if (response.success) {
alert('✓ ' + response.data.message);
} else {
alert('✗ <?php _e('测试失败:', 'argon'); ?> ' + response.data.message);
// wp_send_json_error 的错误消息在 response.data
let errorMsg = response.data || '<?php _e('未知错误', 'argon'); ?>';
alert('✗ <?php _e('测试失败:', 'argon'); ?> ' + errorMsg);
}
$btn.prop('disabled', false).html(originalHtml);
}).fail(function() {
}).fail(function(xhr, status, error) {
// AJAX 请求本身失败
console.error('AJAX Error:', status, error);
alert('<?php _e('请求失败,请重试', 'argon'); ?>');
$btn.prop('disabled', false).html(originalHtml);
});