我正在使用 Codeigniter 和 AngularJS。login.php
当我使用方法和操作提交时,Ci 控制器成功提取了发布数据。但是,当我尝试使用 Angular 提交表单时,它会中断。运行 print_r 时,我什么也没有返回。该脚本甚至成功地从它只是没有发布到 Ci 控制器中app.js
提取值。cred
有任何想法吗?
登录.php
<form ng-submit="login()">
<fieldset>
<legend>Login</legend>
<label>Type your username and password</label>
<input autofocus ng-model="cred.username" type="text" placeholder="Type your username" required><br>
<input ng-model="cred.password" type="password" placeholder="Type your password" required><br>
<button type="submit" class="btn">Submit</button>
</fieldset>
</form>
应用程序.js
app.factory("AuthenticationService", function($http, $location) {
return {
login: function(cred) {
return $http({
method : 'POST',
url : 'index.php/home/login',
data : cred
});
},
};
});
app.controller('LoginController', function($scope, AuthenticationService) {
$scope.cred = { username: "", password: ""};
$scope.login = function() {
AuthenticationService.login($scope.cred);
};
});
CodeIgniter 控制器
public function login() {
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->db->where('username', $username);
$this->db->where('password', $password);
$query = $this->db->get('users');
print_r($_POST);
if ($query->num_rows() > 0) {
$row = $query->row();
echo json_encode(array('isSuccessful' => true));
} else {
echo json_encode(array('flash' => 'Invalid username or password'));
}
}