爲什麼「formvalidation插件」會引發遠程驗證的bug?爲什麼「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));
我講西班牙語替換成功,我使用英文論壇,因爲他們不使用西班牙文的「formvalidation」。我使用谷歌翻譯,因爲我不太懂英文。但我需要解決我的錯誤:( –