Cordova -为什么$http get请求在android设备上失败,但在chrome上工作

Cordova - Why is $http get request failing on android device but working on chrome

本文关键字:失败 但在 工作 chrome android 为什么 http get 请求 Cordova      更新时间:2023-09-26

我在用angular和ionic创建的cordova项目中遇到了这个问题。我已经试过了所有我能做的,但都没有用。

代码如下:

    function getSuccess(response) {
    $scope.modules = response.modules;
    $scope.list = $scope.modules;
    $scope.search = [
        {str: ""}
    ];
}
$http({method: 'GET',
        url: "http://xxx.xxx.xxx.xxx/api/modules"
    })
    .success(getSuccess)
    .error(function (response){
        alert("Damned");
    });

当然,IP是有效的,并在chrome浏览器中工作;)它在我的控制器中。我已经在我的配置文件中添加了<access origin="*"/>,并且在构建后,它仍然在我的android设备上显示"damn"。

Cordova版本:5.0.0Android版本:5.1

安装白名单插件:cordova-plugin-whitelist

从Cordova 5.0.0开始,白名单插件对于跨域请求是强制性的