2016-01-15 50 views
1

得到了一些我无法理解的东西。离子项目,不在电话上工作,但在开发过程中工作

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

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

任何想法家伙?

UPDATE

广东话在Android模拟器中运行它一样好,但使用离子服务于浏览器工作正常。

这是我的一些代码。

的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'); 
}); 

回答

0

发现,这个问题是关系到科尔多瓦插件。

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

只是运行科尔多瓦插件添加科尔多瓦插件白名单在我们的项目文件夹并重建它。

相关问题