【问题标题】:Can't send password via type="password"无法通过 type="password" 发送密码
【发布时间】:2014-03-15 22:27:18
【问题描述】:

我无法弄清楚我的代码有什么问题,我的问题是如果我使用输入类型 =“密码”,我将无法发送发布请求。这是我的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 有什么问题吗?我的问题在于发布/发送数据。

【问题讨论】:

    标签: javascript php angularjs


    【解决方案1】:

    看起来你还没有命名输入。试试这个:&lt;input type="password" name="inputPassword" id="inputPassword" placeholder="Password" ng-model="password" required&gt;

    【讨论】:

    • 我现在看到您的电子邮件输入也有同样的问题。命名它,一切都应该工作。
    • 谢谢@jonlink 的想法 :) 是的,我也是这么想的,我认为这是一个角度问题。
    【解决方案2】:

    在 Laravel 中,在您的用户模型中,passwordremember_token 默认声明为隐藏字段,因此无法在响应中显示:

    class User extends Authenticatable
    {
    
    protected $hidden = [
        'password', 'remember_token',
    ];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-02
      • 2014-09-30
      • 2010-11-05
      • 1970-01-01
      • 2019-06-26
      • 2011-12-06
      相关资源
      最近更新 更多