为什么“formvalidation插件”会在远程验证中引发错误?
使用formvalidation 0.8.1,bootstrap 3和laravel 5.3。
当我使用“远程”验证时,它会向我发送以下错误:
FormValidation.min.js: 4 Uncaught TypeError: b.success is not a function At f (http: // localhost: 8000 / formValidation / formValidation.min.js: 4: 6021) At Object.validate (http: // localhost: 8000 / formValidation / formValidation.min.js: 4: 6890) At FormValidation.Framework.Bootstrap.validateField (http: // localhost: 8000 / formValidation / formValidation.min.js: 1: 27660) At HTMLInputElement. (http: // localhost: 8000 / formValidation / formValidation.min.js: 1: 11025) At HTMLInputElement. (http: // localhost: 8000 / formValidation / formValidation.min.js: 1: 22338) At HTMLInputElement.dispatch (http: // localhost: 8000 / js / jquery.min.js: 3: 10315) At 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));
答案 0 :(得分:0)
未捕获的TypeError:b.success不是函数
我调试了js代码,发现b对象是jqXHR。从JQuery 3.0开始,没有成功的功能。
从jQuery 3.0开始,jqXHR.success(),jqXHR.error()和jqXHR.complete()回调被删除。您可以使用jqXHR.done(),jqXHR.fail()和jqXHR.always()代替。 from jquery.ajax
有两种解决方案: