【发布时间】:2018-02-08 17:21:06
【问题描述】:
我正在尝试从根目录中的 index.html 到我的控制器执行 AJAX 发布。但它在 Firefox 控制台中返回 404 Not Found。
index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<script>
$.ajax(
{
url: "api/postData",
type: "POST",
dataType: 'json',
success: function (result) {
console.debug(result);
alert(result);
},
error: function (xhr, status, p3, p4) {
console.debug(xhr);
var err = "Error " + " " + status + " " + p3;
if (xhr.responseText && xhr.responseText[0] == "{")
err = JSON.parse(xhr.responseText).message;
alert(err);
}
});
</script>
</body>
</html>
我的控制器:
namespace MyAPI.Controllers
{
[Route("api/postData")]
public class MyAPIController : ApiController
{
[HttpPost]
public bool Post()
{
return true;
}
}
}
我需要在 RouteConfig.cs 中设置一些东西吗?
谢谢
【问题讨论】:
标签: ajax asp.net-mvc