而不会导致AJAX错误的responseText是空白不能使用的customErrors? [英] Can't use CustomErrors without causing AJAX error responseText to be blank?

查看:181
本文介绍了而不会导致AJAX错误的responseText是空白不能使用的customErrors?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图调试AJAX错误,我决定关掉的customErrors在我的web.config。其结果是从错误部分的responseText了我所需要的详细消息。因此,尽管的customErrors已开启,则responseText的是空白的。

有没有一种方法,以prevent的responseText的距离是空白,但仍使用的customErrors在web.config?

在话题最近类似的帖子是<一个href="http://stackoverflow.com/questions/9298466/can-i-return-custom-error-from-jsonresult-to-jquery-ajax-error-method">this链接,说,而不是自定义错误过滤器可能是更好的解决方案

下面是一个简单的code我有:

 &LT;的customErrors模式=开的defaultRedirect =〜/ errorpage.htmlredirectMode =ResponseRewrite&GT;
  &LT;错误状态code =404重定向=〜/ filenotfound.htm/&GT;
&LT; /的customErrors&GT;
 

那么这里的错误处理是没有显示的消息,直到我关掉的customErrors:

 错误:函数(XHR,状态,错误){
            的console.log(错误称为');
            的console.log(状态='+状态+错误='+误差);
            的console.log('xhr.responseText ='+ xhr.responseText);
            警报(xhr.status);
            警报(xhr.responseText);
        },
 

解决方案

也许是第一次分析结果与JSON.parse将有助于(取决于所返回)? 如何获得&QUOT;数据&QUOT;现场从xhr.responseText?

While trying to debug an AJAX error I decided to turn OFF customErrors in my web.config. The result was the responseText from the error section had the detailed message I needed. So while customErrors was on, the responseText was blank.

Is there a way to prevent the responseText from being blank but still use customErrors in the web.config?

Closest similar post on the topic is this link that says instead custom error filters might be the better solution

Here is the simple code I had:

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

Then here is the error handling that didn't show a message until I turned off the 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);
        },

解决方案

perhaps parsing the result first with JSON.parse would help (depends on what's returned)? How to get "Data" field from xhr.responseText?

这篇关于而不会导致AJAX错误的responseText是空白不能使用的customErrors?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆