我正在尝试使用AngularJS进行Codeigniter,我正在创建一个简单的登录页面。我遇到的问题是PHP函数“user_logout_process”没有被调用
HTML代码
<section id="login">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="form-wrap" ng-app="validationApp">
<form name="userForm" method="POST" ng-controller="mainController" ng-submit="submitForm()" novalidate> <!-- novalidate prevents HTML5 validation since we will be validating ourselves -->
<h1>Log in with your email account</h1>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="email" name="username" id="name" ng-model="email" class="form-control" placeholder="Email" required>
</div>
<div class="form-group">
<label for="key" class="sr-only">Password</label>
<input type="password" name="password" id="password" ng-model="password" class="form-control" placeholder="Password" required>
</div>
<input type="submit" id="btn-login" class="btn btn-custom btn-lg btn-block" value="Log in">
</form>
</div>
</div> <!-- /.col-xs-12 -->
</div> <!-- /.row -->
</div> <!-- /.container -->
</section>
角色代码
var validationApp = angular.module('validationApp', []);
validationApp.controller('mainController', ['$scope', '$http', '$location', function($scope, $http, $location) {
$scope.submitForm = function() {
$http({
method: 'POST',
url: "authentication/user_login_process",
headers: {'Content-Type': 'application/json'},
data: JSON.stringify({email:$scope.email,password:$scope.password})
}).then(function successCallback(response) {
console.log("success" + response.data);
console.log(JSON.stringify({email:$scope.email,password:$scope.password}));
//$location.path('authentication/user_login_process');
}, function errorCallback(response) {
console.log(response.data);
alert( "failure message: " + JSON.stringify({email:$scope.email,password:$scope.password}));
});
};
}]);
PHP代码
class Authentication extends CI_Controller {
public function __construct() {
parent::__construct();
// Load form helper library
$this->load->helper('form');
// Load form validation library
$this->load->library('form_validation');
// Load session library
$this->load->library('session');
$this->load->model('user_model');
}
public function view($page = 'login'){
if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')){
show_404();
}
$this->load->view('pages/login');
}
public function logout(){
$this->session->sess_destroy();
$data = array(
'error_message' => 'Logout Successful');
$this->load->view('pages/login', $data);
}
public function user_login_process() {
echo "test";
print_r(json_decode(file_get_contents('php://input')));
echo "<script type='text/javascript'>alert(1);</script>";
return "data 1";
}
}
当我检查元素时,我看到帖子能够通过,但按下按钮后页面上没有任何反应,请参见图像的底部。我已经评论并取出了user_login_process(数据库连接)上的大部分代码来测试是否调用了该函数。任何想法?