Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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/9/loops/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_.net_Angularjs_Asp.net Web Api2 - Fatal编程技术网

Javascript 无法从中获得承诺

Javascript 无法从中获得承诺,javascript,.net,angularjs,asp.net-web-api2,Javascript,.net,Angularjs,Asp.net Web Api2,我使用AngularHTTP get请求从.NETWebAPI web服务获取数据,Angular网站和web服务都部署在同一个web服务器上。以下是从服务获取所有网站json列表的服务代码: this.getAllWebsites = function (callback) { return $http.get($rootScope.url + 'GetAllWebsites').success(function (data) { callback(da

我使用AngularHTTP get请求从.NETWebAPI web服务获取数据,Angular网站和web服务都部署在同一个web服务器上。以下是从服务获取所有网站json列表的服务代码:

this.getAllWebsites = function (callback) {
        return $http.get($rootScope.url + 'GetAllWebsites').success(function (data) {
            callback(data)
        });
    }
这就是我在控制器中所做的:

//function triggered at the intialization of controller
    $scope.init = function () {
        $scope.model = [];

        websiteService.getAllWebsites(function (data) {
            $scope.model = data;
            websiteService.paginate($scope);
        });
    };
我的url是正确的,问题是当我调试JavaScript代码时,服务返回数据,否则它不会返回任何数据。我知道问题在承诺中,不会被退回,请建议任何解决方法

this.getAllWebsites = function (callback) {
    return $http.get($rootScope.url + 'GetAllWebsites').then(function (response) {
        return response.data
    });
}
内部控制器

//function triggered at the intialization of controller
$scope.init = function () {
    $scope.model = [];

    websiteService.getAllWebsites().then(function (data) {
        $scope.model = data;
        websiteService.paginate($scope);
    });
};

请尝试“返回回拨数据;”在服务函数中,GET调用应该是这样的:$http.GET'/someUrl',config.thensuccescallback,errorCallback@Dario如果HTTP请求返回promise,那么我们为什么要使用它呢?