首页 > 代码库 > bootstrap 表单validator与ajax验证!!!!
bootstrap 表单validator与ajax验证!!!!
话不多说,代码:
$(document).ready(function() {
$(‘#defaultForm‘).bootstrapValidator({
message: ‘This value is not valid‘,
feedbackIcons: {
valid: ‘glyphicon glyphicon-ok‘,
invalid: ‘glyphicon glyphicon-remove‘,
validating: ‘glyphicon glyphicon-refresh‘
},
fields: {
entry_code: {
validators: {
notEmpty: {
message: ‘验证码不能为空‘
},
stringLength: {
min: 4,
max: 4,
message: ‘验证码长度为4位‘,
},
remote: {
url: CONTROLLER+‘/ajax_check_code‘,
message:"验证码不正确",
type: "get",
dataType: ‘json‘,
data: {
},
delay: 500,
},
}
},
}
});
})
//下面为服务器怎么返回数据实例,看了很多网上都是说返回true、false,然而没软用!!!!!!!气死我了,写的不清不楚,还不如不写,坑人!!!最后找了半天才找到正确的返回格式!下面为代码:
//如果用tp,其它的依葫芦画瓢,只要返回json数据就行! $code = I(‘entry_code‘); if(check_verify($code)) { $this->ajaxReturn(array(‘valid‘=>true,‘message‘=>‘验证码正确‘)); } else { $this->ajaxReturn(array(‘valid‘=>false,‘message‘=>‘验证码不正确‘)); }
bootstrap 表单validator与ajax验证!!!!
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。