【问题标题】:Ionic Project, Not working on phone but working during development离子项目,不在电话上工作,但在开发期间工作
【发布时间】:2016-01-15 01:50:59
【问题描述】:

有一些我无法理解的东西。

我正在学习一个 ionic 框架并创建了一个简单的登录页面,我能够通过编辑器(我正在使用安装了 ionic 实时预览的 Atom 编辑器)以及通过我可以登录或注册的浏览器进行处理,它将带我到下一页。

但很奇怪,当我将项目编译为 .APK 并安装在手机上时,我无法登录或注册。

各位有什么想法吗?

更新

也无法在 android 模拟器中运行它,但在使用 ionic serve 的浏览器中运行良好。

这是我的一些代码。

login.html

<ion-header-bar align-title="center" class="bar-balanced">
  <h1 class="title">Login</h1>
</ion-header-bar>
<ion-view>
    <ion-content class="padding has-header">
      <ion-list>
        <ion-item>
          <input type="text" ng-model="login.username" placeholder="Username">
        </ion-item>
        <ion-item>
          <input type="password" ng-model="login.password" placeholder="Password">
        </ion-item>
      </ion-list>
      <button nav-clear class="button button-block button-balanced" ng-click="LogIn()">Login</button>
      <button class="button button-positive button-clear button-full" ui-sref="signup">Register now!</button>
    </ion-content>
</ion-view>

login.php

<?php
    require_once 'dbConfig.php';
    // check username or password from database
    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);
    $user = $request->username;
    $password = $request->password;

    $results = mysql_query("SELECT email, password FROM tbl_user WHERE email='".$user."' AND password='".$password."' LIMIT 1") or die('{"error":"Login error! Code: 003"}');
    $match  = mysql_num_rows($results);
    if($match > 0 ){
      echo "1";
    }else{
      echo "0";
    }
?>

controller.js

    angular.module('ionicApp.controllers', [])


.controller('AppCtrl', function($scope) {
})


.controller('LoginCtrl', function($scope, $state, $http, $ionicPopup) {
  $scope.showAlert = function(msg) {
      $ionicPopup.alert({
          title: msg.title,
          template: msg.message,
          okText: 'Ok',
          okType: 'button-positive'
      });
    };


  $scope.login = {};
  $scope.LogIn = function() {
    if(!$scope.login.username){
      $scope.showAlert({
        title: "Information",
        message: "Please enter your email address"
      });
    }else if(!$scope.login.password){
      $scope.showAlert({
        title: "Information",
        message: "Please enter your password"
      });
    }else{
      var request = $http({
          method: "post",
          url: "http://www.mywebsite.com/api/login.php",
          data: {
            username: $scope.login.username,
            password: $scope.login.password
          },
          headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        });

        /*Successful HTTP post request or not */

        request.success(function (data){
          if (data == '1'){
            $state.go('app.test');
            }
          else {
            var alertPopup = $ionicPopup.alert({
                  title: 'Login failed!',
                  template: 'Please check your credentials!'
            });
          }
        })
    }
  };
});

app.js

angular.module('ionicApp', ['ionic','ionicApp.controllers'])

.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider

    .state('app', {
      url: "/app",
      abstract: true,
      templateUrl: "templates/menu.html",
      controller: 'AppCtrl'
    })


    .state('app.test', {
      url: '/test',
      views: {
        'menuContent': {
          templateUrl: 'templates/test.html'
        }
      }
    })


    .state('login', {
      url: "/login",
      templateUrl: "templates/login.html",
      controller: 'LoginCtrl'
    });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/login');
});

【问题讨论】:

    标签: javascript php android ionic


    【解决方案1】:

    发现问题与cordova插件有关。

    遇到此问题的任何人都可以尝试此修复。

    只需在我们的项目文件夹中运行 cordova plugin add cordova-plugin-whitelist 并重建它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 2011-03-02
      • 2018-07-11
      • 1970-01-01
      • 2018-07-05
      • 2018-01-25
      • 2021-05-15
      相关资源
      最近更新 更多