通过Jquery Ajax工具返回“不友好”的经典ASP错误消息

时间:2012-09-04 01:53:25

标签: jquery ajax asp-classic

现在已经熟悉Jquery大约6个月了。找到了很多用途,特别是Jquery的Ajax工具。

当我使用.ajax()方法将信息发送到服务器端脚本,并且请求因任何原因失败时,.ajaxerror()和.fail处理程序都将可靠地返回错误消息,但这两种方法似乎想要隐藏我原来熟悉的,不友好但特定的ASP生成的错误消息。

在他们的位置,我得到一个通用的“内部服务器错误”消息。那里的其他经典ASP恐龙知道我在说什么吗?

提前感谢任何见解。

1 个答案:

答案 0 :(得分:1)

使用$ .ajax错误回调函数中提供的xhr.ResponseText。 这是一个例子。

请注意! xhr.response文本返回表示错误页面的所有丑陋的html字符串。 如果你想更具体,还有另一种选择。

在您的服务器端应用程序中使用try和catch子句。 在您发现错误后将其作为文本发送到response.write,然后使用response.end(); 这不是最好的方法,但它会起作用。

另一个选择是使用json构造捕获的错误消息和response.write以及XHR对象将以结构化的oop方式保存信息。

$.ajax({
            type: "POST",
            url: "/Administration/Create",
            data: {
                EntityParentID: data.rslt.parent.attr("id"),
                EntityName: data.rslt.name
            },
            success: function (response)
            {
                var node = data.rslt.obj;
                node.attr("id", response.EntityID);
            },
            error: function (xhr, ajaxOptions, thrownError)
            {
                alert("Error Occured During Creation of Entity.");
                alert(xhr.responseText); //This will alert an ugly html string...
                $.jstree.rollback(data.rlbk);
            },
            dataType: "json"
        });