我正在使用MVC2,并尝试向用户显示友好的错误消息,方法如下:
public ActionResult Foo()
{
Response.StatusCode = 403;
return new ContentResult() { Content="frindly error"}
}
但是,我很难找到如何在ajax OnFailure回调中阅读它:
function ajaxErrorHandler(context) {
// this fires an error, saying it's not a JSON object
alert(context.get_response().get_object());
}
我可以在firebug中看到响应是正确的。 有任何想法吗?
答案 0 :(得分:1)
以下是代码:
alert(context.get_data());
这将显示“frindly error”
答案 1 :(得分:0)
请尝试以下方法: onFailure回调中的context.get_message()...
function OnFailure(context){ 警报(context.get_message());
}
这对我有所帮助。 - Sudipto www.supernovaservices.com