【问题标题】:Unable to load response for 500 internal server error in chrome无法加载 chrome 中 500 内部服务器错误的响应
【发布时间】:2023-03-31 18:20:01
【问题描述】:

我有从 UI 到后端的调用。后端将抛出 500 个内部服务器错误和一些验证(如果有),我必须在前端显示它们。这是它在 Firefox 中的示例图像。Firefox

但是在同一呼叫的 chrome 中,我无法收到任何响应。我不认为这是一个后端问题,因为调用在 Firefox 中工作。我的问题是,我的电话有问题吗?我是否遗漏了必须专门添加到 chrome 中的 ajax 调用的内容?这是来自 chrome 的图片。Chrome issue

来电了。

        $.ajax({
                type: 'GET',
                url: requestUrl,
                data:data,
                async : ajaxHeaders.async,
                success: function(response) {
                    options && options.success && options.success(response);
                },
                error: function(response) {
                    options && options.error && options.error(response);
                }
            });

【问题讨论】:

  • 你手动抛出 500 错误吗?
  • 是的。在后端手动抛出异常(Spring MVC)
  • 为什么不直接返回带有错误键的 JSON?
  • 服务器正在返回 JSON,我可以看到它并在 Firefox 中使用它。该问题仅出现在 Chrome
  • 也许 Chrome 得到错误响应(标题)并忽略任何输出?

标签: javascript jquery ajax google-chrome


【解决方案1】:

我发现了问题所在。 铬有问题。如果分块响应没有正确结束,chrome 无法读取它。但是,Firefox 和 safari 正在内部处理这个问题。

因此解决方案将在后端正确发送分块响应。 Spring MVC 有这个错误。我们可以做的是通过附加我们想要的响应正文来手动发送响应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-25
    • 2013-04-16
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    相关资源
    最近更新 更多