角度js中的异步Jsonp调用

时间:2014-09-24 15:22:29

标签: angularjs jsonp angularjs-scope

在我的角度应用程序中,我需要逐个执行三个jsnop请求。但我只收到最后一次请求回复。我在这里动态构建网址。

$scope.getCurrentMonthData = function(){
        $scope.location_key = 5124302;
        $scope.date = new Date();
        $scope.startday = 1;
        $scope.currentday = $scope.date.getDate()+1;
        $scope.month = $scope.date.getMonth()+1;
        $scope.year = $scope.date.getFullYear();
        $scope.start= $scope.year+'/'+$scope.month+'/'+$scope.startday;

        $scope.end = $scope.year+'/'+$scope.month+'/'+$scope.currentday;

        $scope.url1 = $rootScope.ApiWeatherHost+'/climo/v1/actuals/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.ApiKey+"&callback=JSON_CALLBACK";

        $scope.url2 = $rootScope.ApiWeatherHost+'/climo/v1/records/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.ApiKey+"&callback=JSON_CALLBACK";

        $scope.url3 = $rootScope.ApiWeatherHost+'/climo/v1/normals/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.ApiKey+"&callback=JSON_CALLBACK";

        $http.jsonp($scope.url1).then(function(msg){
          console.log(msg.data);
        });
       $http.jsonp($scope.url2).then(function(msg){
          console.log(msg.data);
        });
        $http.jsonp($scope.url3).then(function(msg){
          console.log(msg.data);
        });

  };

她我没有得到前两个请求。

0 个答案:

没有答案