我有一个ajax帖子,在控制器中我什么也没有回复。如果出现故障,将在下面的代码中显示错误消息吗?
[AcceptVerbs(HttpVerbs.Post)]
public void Edit(Model model)
{
model.Save();
}
$.ajax({
type: "POST",
url: '<%=Url.Action("Edit","test") %>',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function() {
},
error: function(request, status, error) {
alert("Error: " & request.responseText);
}
});
答案 0 :(得分:1)
我建议你返回一个空结果:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Model model)
{
model.Save();
return new EmptyResult();
}
也无需指定数据类型:
$.ajax({
type: "POST",
url: '<%=Url.Action("Edit","test") %>',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
success: function() {
},
error: function(request, status, error) {
alert("Error");
}
});
如果服务器返回的状态代码不是200,则会调用error
回调。