I have an ajax post and in the controller I return nothing. In case there is a failure will the error message displayed with the follwoing code?
[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) {
aler开发者_开发知识库t("Error: " & request.responseText);
}
});
I would recommend you returning an empty result:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Model model)
{
model.Save();
return new EmptyResult();
}
also no need to specify data type:
$.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");
}
});
In case the server returns a status code different than 200 the error
callback will be called.
精彩评论