Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/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
404尝试使用angularjs访问REST服务时_Angularjs_Asp.net Web Api2 - Fatal编程技术网

404尝试使用angularjs访问REST服务时

404尝试使用angularjs访问REST服务时,angularjs,asp.net-web-api2,Angularjs,Asp.net Web Api2,我有一个非常简单的ASP.NET Web API 2项目设置,它只有一个控制器。控制器如下: public class ServiceCodesController : ApiController { // GET api/servicecodes public List<ServiceCode> Get() { ServiceCodeRepository _repo = new ServiceCodeRepository();

我有一个非常简单的ASP.NET Web API 2项目设置,它只有一个控制器。控制器如下:

public class ServiceCodesController : ApiController
{
    // GET api/servicecodes
    public List<ServiceCode> Get()
    {
        ServiceCodeRepository _repo = new ServiceCodeRepository();
        return _repo.ServiceCodes().ToList();
    }
}

angular应用程序正在节点内运行:8000,由@Scott证实这是一个跨域问题。这需要在服务器端设置
JSONP
CORS
。或者在同一端口上运行应用程序和api。

这可能是一个跨域问题。@Chandermani-这是一个跨域问题。请将您的评论更改为回答。最终设置了CORS。遵循本教程
  app.controller('ServiceCodes', function ($scope, $http) {
        $scope.serviceCodes = [];

        $http.get('http://localhost:52491/api/ServiceCodes').
              success(function (data, status, headers, config) {
                  $scope.serviceCodes = data;
              }).
              error(function (data, status, headers, config) {
                  console.log(status + " sent "+ data);
              });  
  });