【发布时间】:2015-06-07 12:14:46
【问题描述】:
我认为有以下 ajax 帖子:
@using (Ajax.BeginForm("UpdateEmail", new AjaxOptions
{
HttpMethod = "POST",
OnFailure = "showMessage(xhr.responseJSON.TypeMessage, xhr.responseJSON.Message)",
OnSuccess = "showMessage(data.TypeMessage, data.Message); location.reload();",
OnBegin = "$('#btnRefresh').attr('disabled', true)",
OnComplete = "$('#btnRefresh').attr('disabled', false)",
}))
还有控制器:
public ActionResult UpdateEmail(EditEmailDTO model)
{
if (isValidCode)
{
//Code here to return a feedback json to be handle in OnSuccess callback - Working OK
return new EmptyResult();
}
else
{
//Here is the problem in production
Response.StatusCode = 422;
feedback = new { Success = false, Message = MessageFeedback.InvalidCode, TypeMessage= TypeMessageFeedback.Error.ToString().ToLower() };
}
catch (InvalidEmailException exception){ //Code Here }
return Json(feedback, JsonRequestBehavior.AllowGet);
}
}
当我在本地调试时,它工作得很好,OnFailure 被触发,我在屏幕上得到反馈。但是当我部署它时,我只是在 Chrome 开发工具控制台上看到服务器返回了 422 错误和这条消息:
Uncaught TypeError: Cannot read property 'TypeMessage' of undefined.
Ajax.BeginForm()中生成的脚本:
(function(xhr,status,error
/**/) {
showMessage(xhr.responseJSON.TypeMessage, xhr.responseJSON.Message)
})
在本地生产和调试是否存在 Response.StatusCode 错误?
【问题讨论】:
标签: javascript ajax asp.net-mvc