Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度请求转到错误函数,而不是成功_Javascript_Angularjs - Fatal编程技术网

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。或者查看
错误
回调中的
数据
错误
值。最有可能的是,问题不在角度方面。我在浏览器中检查了它,它工作正常!您是否检查了浏览器的控制台日志中是否有错误?添加
[路由(“产品/测试”)]
后,它正常工作,我可以知道原因吗?与问题无关(这似乎是服务器端路由问题),但这与您的代码有关: