我无法弄清楚我的代码有什么问题,我的问题是如果我使用输入类型=“密码”,我就无法发送帖子请求。这是我的HTML代码:
<form class="form-horizontal" ng-submit="login()">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email" ng-model="email" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password" ng-model="password" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Sign in</button>
</div>
</div>
和我的Angular控制器:
angular.module('myApp')
.controller('loginController',function($scope,$sanitize,$location,Authenticate){
$scope.login = function(){
Authenticate.save({
'email': $sanitize($scope.email),
'password': $sanitize($scope.password)
},function() {
$scope.flash = ''
$location.path('/pos');
},function(response){
$scope.flash = response.data.flash
})
}
})
我的服务器端php(Laravel):
public function store()
{
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password'));
return Response::json( $credentials );
}
我对Firefox的发布请求:
{"email":"admin@gmail.com","password":""}
并在Chrome上:
email: ""
password: ""
但是如果我删除type="password"
它可以在firefox上传递正确的数据:/我的html / JavaScript有什么问题吗?我的问题在于发布/发送数据。
答案 0 :(得分:0)
看起来你还没有为输入命名。试试这个:<input type="password" name="inputPassword" id="inputPassword" placeholder="Password" ng-model="password" required>
答案 1 :(得分:0)
在Laravel的用户模型中,password
和remember_token
默认声明为隐藏字段,因此无法在响应中显示:
class User extends Authenticatable
{
protected $hidden = [
'password', 'remember_token',
];
}