Javascript 角度请求转到错误函数,而不是成功
以下是控制器代码:Javascript 角度请求转到错误函数,而不是成功,javascript,angularjs,Javascript,Angularjs,以下是控制器代码: [HttpGet] public string test() { return "hi there"; } 这是角度代码: function testFunction() { $http.get('http://localhost:1675/api/Product/test'). success(function (data, status, headers, config) {
[HttpGet]
public string test()
{
return "hi there";
}
这是角度代码:
function testFunction()
{
$http.get('http://localhost:1675/api/Product/test').
success(function (data, status, headers, config) {
alert(data);
}).error(function (data, status, headers, config) {
alert('Error');
});
}
它访问控制器,但进入错误
功能!,当检查数据时
为空!它应该返回hi那里
此代码中有任何错误吗?在添加[Route(“Product/test”)]
后,它会正常工作
[HttpGet]
[Route("Product/test")]
public string test()
{
return "hi there";
}
看起来您的API工作不正常。检查它,可能使用REST客户机或curl。或者查看
错误
回调中的数据
和错误
值。最有可能的是,问题不在角度方面。我在浏览器中检查了它,它工作正常!您是否检查了浏览器的控制台日志中是否有错误?添加[路由(“产品/测试”)]
后,它正常工作,我可以知道原因吗?与问题无关(这似乎是服务器端路由问题),但这与您的代码有关: