离子http获取请求在设备中返回状态0

时间:2015-05-04 10:42:51

标签: angularjs http mobile ionic-framework ionic

我尝试使用http中的get方法从外部URL获取动态数据,它在浏览器中工作正常,但是当我从设备运行它时,get请求不会被处理并返回状态0. CORS也被启用。下面添加控制器以供参考

$scope.getData = function() {
        $http.get("http://somedomain")
            .success(function(data) {
                $scope.firstname = data;

            })
            .error(function(data, status,headers,config) {

      $scope.data = data;
      $scope.status = status;
      $scope.headers = headers;
      $scope.config = config;
            });
    };

1 个答案:

答案 0 :(得分:0)

在我的情况下,它与CORS无关,但在升级到Cordova 5后,我需要添加cordova插件白名单以保持后端请求正常工作:

ionic plugin add cordova-plugin-whitelist

http://forum.ionicframework.com/t/update-to-cordova-5-0-0-make-http-call-error/22703