【问题标题】:Cordova android: Getting 404 error in angular js appCordova android:在 Angular js 应用程序中出现 404 错误
【发布时间】:2015-07-20 06:28:51
【问题描述】:

我正在使用 cordova 和 angularjs(onsenui 前端框架)在 android 中开发应用程序。 这是我从服务器获取一些数据的获取请求

$http.get(url+"getlotterylist").then(function(msg){
        $scope.loading=false;
        $scope.items=msg.data;
    },
    function(err){
        alert("error"+JSON.stringify(err));
          console.log("Error"+JSON.stringify(err));
        }
    );

案例 1

在浏览器中运行应用程序时,我将获得所需的输出(获取请求工作正常)。

案例 2

在 android 平台上构建我的应用程序并导入到 android studio。 此时http get请求返回如下错误

{"data":"","status":404,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url": "http://example.com?action=getlotterylist","headers":{"Accept":"application/json, text/plain, /"}},"statusText":"未找到"}"

还在我的 php 中启用了 CORS

<?php

  header("Access-Control-Allow-Origin: *");
 //api request response
?>

为什么我在手机中运行我的应用程序时收到此错误?

【问题讨论】:

    标签: javascript android angularjs cordova onsen-ui


    【解决方案1】:

    安装 Cordova 白名单插件解决了我的问题

    https://github.com/apache/cordova-plugin-whitelist

    【讨论】:

    • 谢谢!我遇到了同样的问题并且非常沮丧。添加白名单插件也为我解决了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 2017-06-20
    • 2021-12-31
    • 1970-01-01
    相关资源
    最近更新 更多