My following code is working fine and I am able to call API
$.ajax({
url: "http://localhost:57786/mvc/create",
method: "POST",
data: { FirstName: "ABC", LastName: "XYZ" },
success: function (data) {
alert("Success");
},
error: function (statusText, error) {
alert("Error");
}
});
But following code is not working and I am not able to call API
$.ajax({
url: "http://localhost:57786/mvc/create",
method: "POST",
data: JSON.stringify({ FirstName: "ABC", LastName: "XYZ" }),
contentType: "application/json; charset=utf-8",
success: function (data) {
alert("Success");
},
error: function (statusText, error) {
alert("Error");
}
});
Here is API
code
[EnableCors("*","*","*")]
public class MVCController : Controller
{
// POST: MVC/Create
[HttpPost]
public ActionResult Create(MyData value)
{
//My Code
}
}
I am getting response The response had HTTP status code 404.
Why Ajax call is failing when I use contentType
to application/json
?