话不多说,代码:
$(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'=>'验证码不正确')); }