Javascript 使用Ajax和引导模式进行Laravel表单验证的问题
我的引导模式允许用户更新密码:Javascript 使用Ajax和引导模式进行Laravel表单验证的问题,javascript,jquery,ajax,twitter-bootstrap,laravel,Javascript,Jquery,Ajax,Twitter Bootstrap,Laravel,我的引导模式允许用户更新密码: <div class="modal fade" id="settingModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" da
<div class="modal fade" id="settingModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Change Password</h4>
</div>
{!! Form::open(array('url' => '/users/updatePassword', 'method' => 'POST', 'id'=>'passUpdate')) !!}
<div class="modal-body">
@if(Session::has('error'))
<div class="alert-box success">
<h2>{{ Session::get('error') }}</h2>
</div>
@endif
<div id="password-group" class="form-group has-feedback @if ($errors->has('password')) has-error @endif">
{!! Form::password('password', array('id'=>'password', 'class' => 'text input form-control', 'placeholder'=>'New Password')) !!}
<span class="glyphicon glyphicon-lock form-control-feedback @if ($errors->has('password')) has-error @endif"></span>
@if ($errors->has('password')) <p class="help-block">{{ $errors->first('password') }}</p> @endif
<div id ="password_error"></div>
</div>
<div id="password_confirmation-group" class="form-group has-feedback @if ($errors->has('password_confirmation')) has-error @endif">
{!! Form::password('password_confirmation', array('id'=>'password_confirmation', 'class' => 'text input form-control', 'placeholder'=>'Confirm New Password')) !!}
<span class="glyphicon glyphicon-lock form-control-feedback @if ($errors->has('password_confirmation')) has-error @endif"></span>
@if ($errors->has('password_confirmation')) <p class="help-block">{{ $errors->first('password_confirmation') }}</p> @endif
<div id ="password_confirm_error"></div>
</div>
</div>
<div class="modal-footer clearfix">
<button type="button" class=" pull-left btn btn-default btn-flat" data-dismiss="modal">Close</button>
{!! Form::submit('Submit', array('class'=>' pull-right btn btn-primary btn-flat'))!!}
</div>
{!! Form::close()!!}
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
所以我得到了这个问题:
- 在firebug控制台中,我在JS代码的最后一行的参数列表}:之后得到:SyntaxError:missing)
- 另外,我的JS函数$(“#passUpdate”).submit从未被调用
foreach
的)
:
function associate_errors(errors, $form) {
//remove existing error classes and error messages from form groups
$form.find('.form-group').removeClass('has-errors').find('.help-text').text('');
errors.foreach(function (value, index) {
//find each form group, which is given a unique id based on the form field's name
var $group = $form.find('#' + index + '-group');
//add the error class and set the error text
$group.addClass('has-errors').find('.help-text').text(value);
});
}
注意上面最后一行的第二行
}))
是的,谢谢,这解决了第一部分,但它仍然在空白页中打印JSON响应,而不是在ModalIs
submit()
called中显示错误?是的,被调用了我在这里被打印了,我还添加了类似于此函数的e(e)尝试在失败和成功块中的post
success callbackConsole.log中打印response
$validator = Validator::make($data, $rules);
if ($validator->fails()){
// If validation fails redirect back to login.
return Response::json(array(
'fail' => true,
'errors' => $validator->getMessageBag()->toArray()
));
}
function associate_errors(errors, $form) {
//remove existing error classes and error messages from form groups
$form.find('.form-group').removeClass('has-errors').find('.help-text').text('');
errors.foreach(function (value, index) {
//find each form group, which is given a unique id based on the form field's name
var $group = $form.find('#' + index + '-group');
//add the error class and set the error text
$group.addClass('has-errors').find('.help-text').text(value);
});
}