得到了我无法理解的东西。
我正在学习离子框架并创建了一个简单的登录页面,我能够通过编辑器进行处理(我使用安装了离子实时预览的Atom编辑器)以及我可以登录或注册的浏览器,它将会带我到下一页。
但是真的很奇怪,当我将项目编译成.APK并安装在我的手机上时,我无法登录或注册。
任何想法的人?
更新
也可以在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 :(得分:0)
发现,问题与cordova插件有关。
遇到此问题的任何人都可以尝试此修复程序。
在我们的项目文件夹中运行 cordova插件添加cordova-plugin-whitelist 并重建它。