I'm using Jquery for my JSON post and get.
The problem I have is I don't know how to respond from my MVC controller to make it hit the 'failure'.
I'm using MVC.NET, I'm not using web.api
My ajax should be familiar (The code snippets has variables already defined):
$.ajax({
type: type,
url: url,
contentType: "application/json;",
data: data,
dataType: "json",
success: function (response) {
successDelegate(response);
},
failure: function (e) {
failDelegate(e.statusText);
},
error: function (e) {
errorDelegate(e.statusText);
}
The problem I have is every time I return it hits the success.
So my MVC controller could be
[HttpPost]
public JsonResult Create()
{
//logic removed
return Json(new { IsError = true, Message = "The captcha code is not vaid" });
}
I see why it's hitting the success ... it's returning as I want, and I could simply validate the IsError
but it would be better to return it in a way where the AJAX knows if it's success or failure.
I have read Send JSON data via POST (ajax) and receive json response from Controller (MVC) but this about just receiving a response (which I have working), not about the type of response (how to make the response go to Failure, not sucess).