【问题标题】:PhoneGap - Angularjs http service (PHP API call) Not WorkingPhoneGap - Angularjs http 服务(PHP API 调用)不工作
【发布时间】:2018-09-25 21:07:08
【问题描述】:

我尝试使用 Angularjs http 服务 来调用我的 PHP API。在浏览器中一切正常。但是,当我在我的 Android 手机上测试它时,它不起作用。

我的问题:

在 Android PhoneGap 应用程序中,每当我触发 Angularjs http 服务时,它总是会触发function (error),即使手机已连接到互联网。

我试过看看这个,但他们的解决方案不起作用:

  1. Angular $http.get() does not work in Phonegap DevApp
  2. Cordova 5.3.1 Android app can't access the internet

我还确保 Phonegap config.xml 允许 Internet 访问权限:

<access allows-arbitrary-loads-in-media="true" allows-arbitrary-loads-in-web-content="true" allows-local-networking="true" origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />

但是还是不行。

我的问题:

  1. Angularjs http 服务不能在 PhoneGap 移动应用程序上工作,而只能在 Web 浏览器上工作吗?
  2. 除了config.xml之外,还有没有其他配置可以让PhoneGap Mobile App访问互联网?

Angularjs 代码:

$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';

$http({
    method: 'POST',
    data: {
        'email' : $scope.email,
        'password' : $scope.password,
    },
    url: 'https://unsurfaced-cross.000webhostapp.com/PGLogin.php'
 }).then(function (response){
    $scope.users = response.data;

    if(response.data[0]=="LOGIN"){
      alert("Successful Login");
      $window.location.href = './homepage.html';

    }else{
      alert("Login Failed. Incorrect Email or Password.");
    }

 },function (error){
      alert("Please ensure You are connected to Internet.");
 });

【问题讨论】:

  • 错误回调中的错误说明了什么?

标签: android angularjs cordova phonegap angularjs-http


【解决方案1】:

似乎实际上我只是没有安装whitelist 插件,就我而言,默认情况下没有安装whitelist 插件。

由于我使用的是PhoneGap,而不是使用cordova-plugin-whitelist@latestcordova createcordova plugin add cordova-plugin-whitelist等命令。

我应该使用:phonegap plugin add cordova-plugin-whitelist

安装白名单插件后,一切正常。

所以,

  1. Angularjs http 服务可以在 PhoneGap 移动应用上运行。
  2. 除了 config.xml 之外,我们还必须确保安装了所有必要和必需的插件,例如白名单插件。

【讨论】:

  • 这对我不起作用,我还添加和删除了插件以确保
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-20
  • 1970-01-01
  • 2017-04-27
  • 2018-01-28
  • 2016-10-01
  • 2023-03-04
  • 2016-01-09
相关资源
最近更新 更多