本文介绍了为什么要使用"formvalidation插件"在远程验证中抛出一个错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么"formvalidation插件"在远程验证中引发了我的错误?

Why "formvalidation plugin" throws me a bug in remote validation?

使用formvalidation 0.8.1,bootstrap 3和laravel 5.3.

Use formvalidation 0.8.1, bootstrap 3 and laravel 5.3.

当我使用远程"验证时,它会向我发送以下错误:

When I make use of "remote" validation it sends me the following error:


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));

推荐答案

我调试了js代码,发现b对象是jqXHR.从JQuery 3.0开始,没有成功功能.

I debug the js code and find b object is jqXHR. Since JQuery 3.0, there is no success function.

有两种解决方案:

  1. 使用旧版本的jQuery(< 3.0)
  2. 修改formvalidation代码,将成功替换为完成,将错误替换为失败

这篇关于为什么要使用"formvalidation插件"在远程验证中抛出一个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 22:08