C# MVC3。返回500状态代码时浏览器自身发出警报
您好,当返回C# MVC3。返回500状态代码时浏览器自身发出警报,c#,asp.net-mvc-3,jquery,http-status-codes,C#,Asp.net Mvc 3,Jquery,Http Status Codes,您好,当返回HttpStatusCodeResult对象时,如何防止浏览器自身发出警报 行动方法: [HttpPost] public ActionResult Finish() { //Throw the status code result return new HttpStatusCodeResult(500,"Oops something wrong happened!"); } 剧
HttpStatusCodeResult
对象时,如何防止浏览器自身发出警报
行动方法:
[HttpPost]
public ActionResult Finish()
{
//Throw the status code result
return new HttpStatusCodeResult(500,"Oops something wrong happened!");
}
剧本
jQuery.ajax({
url: '@Url.Action("Finish","Home")',
type: "POST",
success : function(result) {
alert("success is:"+result);
},
error: function (response, status, errorThrown) {
alert(errorThrown);
}
});
调用Finish()操作的结果显示在alert()中代码>函数,但是
在自定义警报下,
浏览器还会发出警告,提示信息为“由于发生内部服务器错误,无法显示页面。”
解决方案
正如塔纳索斯指出的那样,实际问题是一个全局函数:
jQuery(document).ajaxError(function (e, jqxhr, settings, exception) {
if (jqxhr != null) {
alert(jqxhr.responseText);
}
非常感谢你的帮助。问题结束。也许在您的项目中,已经有一个较低级别的ajax错误捕获,比如ajax设置或
另外,jQuery是唯一实现的框架吗?try catch blocks是您要查找的内容检查web.config文件中system.web中的customErrors标记,它是否具有defaultRedirect属性?也许它会重定向到提供警报的页面?