我从服务器收到json响应:
{"success":false,"register_email":"","register_firstname":"","register_lastname":"<p>Please enter last name.<\/p>","register_password":"<p>Please enter your password.<\/p>","register_repeat_password":"<p>Please retype your password.<\/p>","register_about":"<p>Enter atleast 50 characters long.<\/p>"}
现在,我需要使用jquery验证器在我的html页面中显示这些错误。
<div class="form-group">
<label for="lastname" class="col-md-3 control-label">Last Name</label>
<div class="col-md-9">
<input type="text" class="form-control" name="register_lastname" placeholder="Last Name">
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-3 control-label">Password</label>
<div class="col-md-9">
<input type="password" class="form-control" id="register_password" name="register_password" placeholder="Password">
</div>
</div>
在前端检查的情况下,我成功使用了jquery验证器。
$('#signupform').validate({
rules: {
register_email: {
required:true,
email:true
},
register_firstname: "required",
register_lastname: "required",
register_password: {
required:true,
minlength:6
},
register_repeat_password: {
required:true,
equalTo: "#register_password"
},
register_about: {
required:true,minlength:50
},
},
messages: {
register_email: "Please Enter your email.",
register_firstname: "Enter your first name",
register_lastname: "Enter your last name.",
register_password: {
required: "Please enter your password.",
minlength: "Your password should be of minimum 8 characters."
},
register_repeat_password: {
required: "Please retype your password",
equalTo: "Your password don't match."
},
register_about: "Please Enter at least 50 characters."
},
errorElement: 'div',
errorClass: 'alert alert-danger fade in',
我希望在后端检查时实现相同目的。
我用谷歌搜索,我在jquery验证器中了解了remote
属性,但它一次只适用于一个字段。我想在每个案例中整合后端响应。