【问题标题】:Cordova - Why is $http get request failing on android device but working on chromeCordova - 为什么 $http get 请求在 android 设备上失败但在 chrome 上工作
【发布时间】:2015-08-07 08:47:49
【问题描述】:

我在我的 cordova 项目中遇到了这个问题,该项目是用 angular 和 ionic 创建的。我已经尽我所能,但还是不行。

代码如下:

    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="*"/>,构建后它仍然在我的安卓设备上显示“该死的”。

科尔多瓦版本:5.0.0 安卓版本:5.1

【问题讨论】:

  • response 应该包含有关错误的详细信息。当您可以确切地知道出了什么问题时,不要输出固定(无用)的错误消息。
  • 我实际上想使用console.log之类的东西,但我不知道如何在应用程序中做到这一点,知道吗? ://
  • 甚至像 alert(JSON.stringify(response)) 这样的东西也可以提供帮助。任何东西都可以让错误对象的内容显示出来并可以查看。
  • 安装白名单插件cordova-plugin-whitelist(而且我不搞乱ZOHANNNN)
  • @aorfevre 发表您的评论作为答案,我会给它+1000。你只是救了我的命!特维姆!

标签: javascript android angularjs cordova ionic-framework


【解决方案1】:

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

自 Cordova 5.0.0 起,跨域请求必须使用白名单插件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-11
    • 2020-07-05
    • 2019-10-21
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    相关资源
    最近更新 更多