[英]Ionic Project, Not working on phone but working during development
有我不明白的東西。
我正在學習一個ionic框架並創建了一個簡單的登錄頁面,我能夠通過編輯器進行處理(我正在使用安裝有ionic live Preview的Atom Editor)以及通過瀏覽器進行登錄或注冊,它將帶我進入下一頁。
但是真的很奇怪,當我將該項目編譯為.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');
});
發現,問題與cordova插件有關。
遇到此問題的任何人都可以嘗試此修復程序。
只需運行cordova插件,在我們的項目文件夾中添加cordova-plugin-whitelist並重建它即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.