2016-01-15 49 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

發現,這個問題是關係到科爾多瓦插件。

任何遇到此問題的人都可以嘗試此修補程序。

只是運行科爾多瓦插件添加科爾多瓦插件白名單在我們的項目文件夾並重建它。

相關問題