【问题标题】:Can't use CustomErrors without causing AJAX error responseText to be blank?不能在不导致 AJAX 错误 responseText 为空白的情况下使用 CustomErrors?
【发布时间】:2015-09-14 20:08:45
【问题描述】:

在尝试调试 AJAX 错误时,我决定在我的 web.config 中关闭 customErrors。结果是错误部分的 responseText 包含我需要的详细消息。因此,当 customErrors 开启时,responseText 是空白的。

有没有办法防止 responseText 为空白但仍然在 web.config 中使用 customErrors?

与该主题最接近的类似帖子是this link that says instead custom error filters might be the better solution

这是我的简单代码:

<customErrors mode="On" defaultRedirect="~/errorpage.html" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="~/filenotfound.htm" />
</customErrors>

然后这里是在我关闭 customErrors 之前没有显示消息的错误处理:

        error: function (xhr, status, error) {
            console.log('error called');
            console.log('status = ' + status + ' error= ' + error);
            console.log('xhr.responseText = ' + xhr.responseText);
            alert(xhr.status);
            alert(xhr.responseText);
        },

【问题讨论】:

    标签: jquery asp.net ajax


    【解决方案1】:

    也许先用 JSON.parse 解析结果会有所帮助(取决于返回的内容)? How to get "Data" field from xhr.responseText?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 2019-12-05
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 2011-05-28
      相关资源
      最近更新 更多