2
我使用「jQuery的驗證」 https://github.com/jzaefferer/jquery-validation來驗證我的形式,jQuery的:形式不能使用`jQuery的validation`的遠程確認後提交
有一個問題,那就是:
表單在使用jquery-validation的遠程驗證後無法提交。如果遠程方法被刪除,那就沒問題。
我該怎麼辦?提前致謝。
觀點:
<form id="register" class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{!! csrf_field() !!}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="name" id="name" value="{{ old('name') }}">
@if ($errors->has('name'))
<span class="help-block"><strong>{{ $errors->first('name') }}</strong></span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" id="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block"><strong>{{ $errors->first('email') }}</strong></span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password" id="password">
@if ($errors->has('password'))
<span class="help-block"><strong>{{ $errors->first('password') }}</strong></span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password_confirmation" id="password_confirmation">
@if ($errors->has('password_confirmation'))
<span class="help-block"><strong>{{ $errors->first('password_confirmation') }}</strong></span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-user"></i>Register
</button>
</div>
</div>
</form>
的javascript:
<script>
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$("#register").validate({
rules: {
name: {
required: true,
rangelength: [4, 30],
remote: {
url: "{{url('services/validation/verify_name')}}",
type: "post"
}
},
email: {
required: true,
email: true,
minlength: 9,
maxlength: 30,
remote: {
url: "{{url('services/validation/verify_email')}}",
type: "post"
}
},
password: {
required: true,
rangelength: [6, 20]
},
"password_confirmation": {
equalTo: "#password"
}
},
errorClass: "has-danger",
success: function (label, elem) {
var element = $(elem);
if (element.is('input[name="name"]')) {
label.html("available");
} else if (element.is('input[name="email"]')) {
label.html("available");
}
},
highlight: function (element, errorClass) {
$(element).fadeOut(function() {
$(element).fadeIn();
});
$(element).closest(".form-group").addClass(errorClass);
},
unhighlight: function (element, errorClass) {
$(element).closest(".form-group").removeClass(errorClass);
},
errorPlacement: function (error, element) {
error.insertAfter(element);
}
});
});
</script>
服務器返回的遠程請求是什麼?可以檢查使用瀏覽器開發工具在網絡選項卡 – charlietfl
謝謝,我應該更改URL像'url:「{{url('services/validation/verify_name')}}」'到'url:「services/validation/verify_name」 – zwl1619