为什么" formvalidation插件"在远程验证中给我一个错误?
使用FormValidation 0.8.1,Bootstrap 3和Laravel 5.3。
当我使用"远程"验证时,它会给我发送以下错误:
formvalidation.min.js:4未熟悉的typeError:B.Success不是功能在f(http://localhost:8000/formvalidation/formvalidation.min.js:4:6021)在object..validate(http://localhost:8000/formvalidation/formvalidation.min.js:4:6890)在FormValidation.framework.bootstrap.validatefield(http://localhost:8000/formValidation/formValidation.min.js:1:27660)在htmlinputelement。(http://localhost:8000/formvalidation/formValidation.min.js:1:11025)在htmlinputelement。(http://localhost:8000/formvalidation/formValidation.min.js:1:22338)在htmlinputelement.dispatch(http://localhost:8000/js/jquery.min.js:3:10315)在htmlinputelement.q.handle(http://localhost:8000/js/jquery.min.js:3:8342)
为什么?
查看:
<div id="ModalCrear" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-tittle">Crear</h4>
</div>
<form class="form-horizontal" role="form" id="form-crear">
<div class="modal-body">
<div class="form-group">
<label for="CrearNombre" class="control-label col-sm-2">Nombre: </label>
<div class="col-sm-10">
<input type="text" class="form-control" id="CrearNombre" name="CrearNombre">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
<span class="glyphicon glyphicon-remove"></span> Cerrar
</button>
<button type="button" id="Guardar" class="btn btn-primary" disabled="disabled">
<span class="fa fa-save"> Guardar</span>
</button>
</div>
</form>
</div>
</div>
</div>
jQuery:
$('#form-crear').formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
CrearNombre: {
validators: {
notEmpty: {
message: 'El campo Nombre es requerido'
},
stringLength: {
min: 5,
max: 30,
message: 'El Nombre de 5 a 30 caracteres de largo'
},
regexp: {
regexp: /^[a-zA-Z]+$/,
message: 'El Nombre solo puede contener letras'
},
remote: {
message: 'El Cargo ya esta registrado',
url: "cargos/comprobacion",
type: "post",
async: true
}
}
}
}
});
控制器:
$isAvailable = true;
if (Cargos::where('nombre', 'ilike', $req->get('CrearNombre'))->exists()) {
$isAvailable = true;
} else {
$isAvailable = false;
}
return Response::json(array('valid' => $isAvailable));
untureck typeError:B.Success不是函数
i调试JS代码并找到B对象是JQXHR。由于jQuery 3.0,没有成功函数。
jqxhr.success(),jqxhr.error()和jqxhr.complete()回调从jquery 3.0开始删除。您可以使用jqxhr.done(),jqxhr.fail()和jqxhr.always()。来自jquery.ajax
有两种解决方案:
- 使用旧版本jquery(&lt; 3.0)
- 修改形式验证代码,用完成的成功替换成功,失败