AngularJS:$ HTTP.GET是越来越取消AngularJS、HTTP、GET

2023-09-13 04:38:25 作者:九封至尊

我想使用angularJS的$ http服务,但它似乎并没有工作。我已经在网上阅读约占这样一个问题,但考虑到解决方案并不能帮助。我已经在我的控制器以下内容:

I am trying to use $http service of angularJS but it doesn't seem to work. I have read up online about such an issue but the solutions given doesn't help. I have the following in my controller:

app.controller('Ctrl', function($scope, $http){    
    var url = http://someurl?name=foo;
    $scope.submitRules = function(){
        $http({method: 'GET', url: url}).
              success(function(data, status) {
                $scope.status = status;
                $scope.data = data;
              }).
              error(function(data, status) {
                $scope.data = data || "Request failed";
                $scope.status = status;
              });
    };
});

我使用这个版本angularJS的&LT;脚本src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js\"></script>

每当我尝试发送它表明请求状态的取消的请求。 ,我发送请求的URL是很好的工作,它只是不工作形式angularJS。有人可以帮忙吗?

Whenever I try sending the request it shows that the request status is cancelled. The URL that I am sending the request to is very well working it just doesn't work form angularJS. Can someone help?

推荐答案

如果这不是CORS,您可以检查使用铬与CORS扩展,尝试设置您的请求超时:

If it's not CORS, which you can check using chromium with CORS extension, try to set timeout of your request:

app.controller('Ctrl', function($scope, $http){    
    var url = http://someurl?name=foo;
    $scope.submitRules = function(){
        $http({
            method: 'GET',
            url: url,
            timeout: 50000
        }).
        success(function(data, status) {
          $scope.status = status;
          $scope.data = data;
        }).
        error(function(data, status) {
          $scope.data = data || "Request failed";
          $scope.status = status;
        });
    };
});

设置$ httpProvider的从不工作对我来说,这是相当服务器问题。

Setting $httpProvider never worked for me, it's rather server matter.