【发布时间】:2021-03-30 23:31:29
【问题描述】:
这是我在 .Net 中用于 web api 2.0 的控制器代码
当我使用邮递员时,它工作正常,但是当我从 HTML 页面调用它时,我收到错误 No HTTP resource was found that matches the request URI
我做错了什么?
控制器代码
[HttpPost]
public IHttpActionResult GetCustomerName (string num)
{
return Json(new
{
success = true,
message = "My Name "+ num,
});
}
HTML 代码
$.ajax({
url: "http://localhost:10000/api/CFP/GetCustomerName",
type: "POST",
data: {
'num': '123'
},
contentType: 'application/json; charset=utf-8',
success: function (response) {
alert(response.message);
},
error: function (xhr, error, thrown) {
alert(xhr.responseText);
}
});
【问题讨论】:
标签: .net ajax postman asp.net-web-api2