I'm trying to return a status code to my web page. But I'm getting back a 200 and not the 201 that my controller is getting back back, which means my alert is not showing.
Any ideas what i'm doing wrong?
$.ajax({
url: "/Home/Request/",
type: 'POST',
data: { model: JSON.stringify(model) },
cache: false,
crossDomain: true,
async: false,
dataType: 'json',
statusCode: {
201: function(data) {
alert(data);
},
501: function(data) {
alert('Opps an error occurred.');
}
},
error: function(event) {
alert('Error' + event);
}
});
//Controller
[HttpPost]
public async Task<JsonResult> Request(string model)
{
//Do Stuff
return Json((int)response.StatusCode, JsonRequestBehavior.AllowGet); <-- response.StatusCode = 201
}
return Json((int)response.StatusCode...is going to return the status code as the response body, not set the HTTP status response to the request.