使用ajax帖子的BootStrap模式Formvalidation

时间:2015-12-28 10:59:50

标签: jquery ajax twitter-bootstrap

我使用bootstrap模式时遇到问题。重点是更新模态

中显示的字段

这是我的模态代码

<div id="myModalAtiv" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="alert alert-info" id="myModalLabel"><span class="glyphicon glyphicon-pencil"></span> Edição de Atividades</h4>
                </div>
                <div class="modal-body">
                    <form id="editAtiv">
                        <div class="form-group">
                            <input type="hidden" name="idativade" id="idativade">
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">Cargo:</label>
                            <input class="form-control" name="cargo" id="cargo" disabled="true">
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">Atividade:</label>
                           <textarea class="form-control" rows="2" name="atividade" id="atividade"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">Data:</label>
                            <input class="form-control" name="data" id="data">
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">Hora:</label>
                            <input class="form-control" name="hora" id="hora">
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">Local:</label>
                            <input class="form-control" name="local" id="local">
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">Intervenientes:</label>
                            <input class="form-control" name="inter" id="inter">
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">Destinatários:</label>
                            <textarea class="form-control" rows="2" name="dest" id="dest"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">Notas:</label>
                            <input class="form-control" name="notas" id="notas">
                        </div>
                        <div class="form-group">
                            <label for="plano">PAE:</label>
                            <div class="radio">
                                <label><input type="radio" name="optradio" value="Não" id="optradio">Não</label>
                            </div>
                            <div class="radio">
                                <label><input type="radio" name="optradio" value="Sim" id="optradio">Sim</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <input type="hidden" class="form-control" name="editarAtiv" id="editarAtiv" value="editarAtiv">
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="submit" name="submitButton" class="btn btn-info">Atualizar</button>
                    <button type="button" class="btn btn-default"data-dismiss="modal">Fechar</button>
                </div>
                </form>
            </div><!-- End of Modal body -->
        </div><!-- End of Modal content -->
    </div><!-- End of Modal dialog -->

我的ajax电话是

<script>
    $(document).ready(function() {
        $('#editAtiv')
            .formValidation({
                framework: 'bootstrap',
                icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    optradio: {
                        validators: {
                            notEmpty: {
                                message: 'Deve definir se faz parte do Plano Anual de Escola'
                            }
                        }
                    }
                }
            })
            .on('success.form.fv', function(e) {
                console.log("aqui");
                e.preventDefault();
                var $form = $(e.target),
                fv    = $form.data('formValidation'); 
                $.ajax({
                url: 'updates.php',
                type: 'POST',
                data: $form.serialize(),
                success: function(data){
                   alert(data);
               }

            });
        });
    });
    </script>

我有所有的库

    <script src="js/formValidation.min.js"></script> 
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap.min2.js"></script>
    <script src="js/bootstrap-table.js"></script>
    <script src="js/bootstrap-table-export.js"></script>
    <script src="js/bootstrap-table-pt-PT.js"></script>
    <script type="text/javascript" src="js/tableExport.js"></script>
    <script type="text/javascript" src="js/jquery.base64.js"></script>
    <script type="text/javascript" src="js/sprintf.js"></script>
    <script type="text/javascript" src="js/jspdf.js"></script>
    <script type="text/javascript" src="js/base64.js"></script>

当我点击提交按钮时,没有任何反应,但我的表单ID为&#34; editAtiv&#34;

我失踪了什么?

1 个答案:

答案 0 :(得分:0)

问题出在这里

 </form>
            </div>
            <div class="modal-footer">
                <button type="submit" name="submitButton" class="btn btn-info">Atualizar</button>
                <button type="button" class="btn btn-default"data-dismiss="modal">Fechar</button>
            </div>
            </form>

两次..