Serialize does not load after Ajax request

Asked

Viewed 147 times

1

I have a query that brings the result of the database to a table that at each row of the result has option to edit, until then the query and run normal, after clicking edit it loads the function SELECIONA_EDITAR_DOCUMENTO, I had to call the issue by onclick for each query line have a form. It loads the normal editing page, plus when clicking edit document it loads the function CONFIRMAR_EDITAR_DOCUMENTO but carries nothing of jQuery, for example jQuery("#CONFIRMAR_EDITAR").serialize() he does not carry the input text, more if I pass each input by $('#consulta_ano').val() within the data of Ajax it carries normal. I called a console.log(dados) after the serialize and simply returns blank.

Call for consultation (functions.js):

jQuery(document).ready(function(){
    jQuery('#CONSULTA_RAPIDA').submit(function(){
        var dados = jQuery( this ).serialize();
        var request = $.ajax({
                url: "lib/class.consulta.php",
                method: "POST",
                data: dados,
                dataType: "html",
                beforeSend: function(){$('#carregando').show();},

            });
            request.done(function( msg ) {
                $(".conteudo_consulta").html(msg);
                $('#carregando').hide();
            });

            request.fail(function( jqXHR, textStatus ) {
                vex.dialog.alert( "Request failed: " + textStatus );
            });

        return false;
    });

Call for editing:

function SELECIONA_EDITAR_DOCUMENTO(id) {
        var dados = jQuery('#SELECIONAR_EDITAR'+id).serialize();
        console.log(dados);
        var request = $.ajax({
                url: "lib/class.consulta.php",
                method: "POST",
                data: dados,
                dataType: "html",
                beforeSend: function(){$('#carregando').show();},

            });
            request.done(function( msg ) {


                $(".conteudo_consulta").html(msg);
                $('#carregando').hide();
            });

            request.fail(function( jqXHR, textStatus ) {
                vex.dialog.alert( "Request failed: " + textStatus );
            });
}

Confirm editing:

function CONFIRMAR_EDITAR_DOCUMENTO() {
var dados = jQuery("#CONFIRMAR_EDITAR").serialize();
console.log(dados);
vex.defaultOptions.className = 'vex-theme-default';
vex.dialog.confirm({
    message: 'Deseja realmente editar o documento?',
    callback: function(aceita) {
        if (aceita) {
            var request = $.ajax({
                url: "lib/class.consulta.php",
                method: "POST",
                data: dados,
                beforeSend: function(){$('#carregando').show();},
                dataType: "html"
            });

            request.done(function( msg ) {
                $('#carregando').hide();
                vex.dialog.alert({
                    message: msg,
                    callback: function(resultado_2){
                        if(resultado_2){
                            window.location.reload()
                        }
                    }
                });
            });

            request.fail(function( jqXHR, textStatus ) {
                vex.dialog.alert( "Request failed: " + textStatus );
            });
        }
    }
});
return false;
}

html:

            <table>
            <form style="border: 2px inset; padding: 10px" id="CONFIRMAR_EDITAR" name='CONFIRMAR_EDITAR' enctype="multipart/form-data" method="POST">
            <tr><td align='right'>Prefixo:</td> <td><input style="text-align: center; border: 1px inset; font-color:#E8E8E8" size="1" name='prefixo_editar_confirma' id="prefixo_editar_confirma" type="text" value="<?php echo $linha['prefixo']; ?>" readonly /> <br /></td></tr>
            <tr><td align='right'>Código:</td> <td><input style="text-align: center; border: 1px inset" name="sequencial_editar" id="sequencial_editar" size="2" type="text" value="<?php echo $linha['sequencial']; ?>" readonly /> <br /></td></tr>
            <tr><td align='right'>Ato: </td> <td><input style="text-align: center; border: 1px inset" name="ato_editar" id="ato_editar" type="text" size="8" value="<?php echo $linha['ato']; ?>" readonly /> <br /></td></tr>
            <tr><td align='right'>Número: </td> <td><input style="text-align: center; border: 1px inset" name="numero_editar" id="numero_editar" type="number" min="1" max="5000" value="<?php echo $linha['numero']; ?>" /> / <input style="text-align: center; border: 1px inset" type="number" min="1970" max="2040" name="ano" id='ano' value="<?php echo $linha['ano']; ?>" /></td></tr>
            <tr><td align='right'>Súmula: </td> <td><textarea style="border: 1px inset; resize: none" name="sumula_editar" id="sumula_editar" type="text" cols="100" rows="4" ><?php echo $linha['sumula']; ?></textarea><br /></td></tr>
            <tr><td align='right'>Texto: </td> <td><textarea style="border: 1px inset; resize: none" name="texto_editar" id="texto_editar" type="text" cols="100" rows="10" ><?php echo $linha['texto']; ?></textarea><br /></td></tr>
            <tr><td align='right'>Nome do arquivo: </td> <td><input style="border: 1px inset" name="arquivo" id="arquivo" type="text"  size="40" value="<?php echo substr($linha['arquivo'], 12); ?>" readonly /> <br /></td></tr>
            <tr><td align='right'>Usuário: </td> <td><input style="border: 1px inset" name="usuario_ins_editar" id="usuario_ins_editar" type="text"  size="16" value="<?php echo $linha['usuario_ins']; ?>" readonly /> <input name="data_ins" id="data_ins_editar" type="text"  size="13" style="border: 1px inset" value="<?php echo date_format(new DateTime($linha['data_ins']), "d/m/Y H:i:s"); ?>" readonly /><br /></td></tr>
            <tr><td align='right'>Última modificação: </td> <td><input style="border: 1px inset" id="usuario_ult_mod_editar" type="text"  size="16" value="<?php echo $linha['usuario_ult_mod']; ?>" readonly /> <input name="data_ult_mod" id="data_ult_mod_editar" type="text"  size="13" style="border: 1px inset" value="<?php echo date_format(new DateTime($linha['data_ult_mod']), "d/m/Y H:i:s"); ?>" readonly /><br /></td></tr>
            <tr><td align='right'>Alterar arquivo: </td> <td><input style="border: 1px inset" id='Habilita_Arquivo_Check' id="Habilita_Arquivo_Check" type="checkbox" onChange="HabilitaArquivoCheck()" title="Sim"/><br /></td></tr>
            <tr><td align="right" hidden id="HabilitaColunaArquivo">Arquivo: </td><td hidden id="HabilitaColunaArquivoSelecao"><input style="border: 1px inset" name="arquivo_editar" id="arquivo_editar" type="file" title="Arquivo com extensão pdf" accept=".pdf"/><br /> </td></tr><br />
            <tr><td align='right'>Dados da Publicação: </td> <td><input name='Habilita_Publicação_Check' id="Habilita_Publicação_Check" type="checkbox" style="border: 1px inset" onclick="HabilitaPublicaçãoCheck()" <?php if($linha['orgao_pub'] != ''){ echo "checked";}?> /> <br /></td></tr>
            </table>
            <div <?php if($linha['orgao_pub'] == ''){ echo "hidden";}?> id="HabilitaPublicação">
            <table>
            <tr><td align='right'>Orgão de publicação: </td> 
                <td><select id="orgao_pub" id='orgao_pub' name="orgao_pub">
                    <option value="" <?php if($linha['orgao_pub'] == ''){echo "selected";}?>> Nenhum selecionado</option>
                    <?php while($prod = mysql_fetch_array($correios)) { ?>
                    <option value="<?php echo $prod['nome_abrev'] ?>"
                    <?php if($linha['orgao_pub'] == $prod['nome_abrev']){echo "selected";}?>><?php echo $prod['nome_abrev'] ?></option>
                    <?php } ?>
                </select></td>
            <td align='right'>   Data de publicação: </td><td><input class="data_pub" onKeyUp="data(this)" maxlength='10' id="calendario" name="data_pub_editar"type="text" value="<?php echo $linha['data_pub']; ?>" size="6" style="border: 1px inset" /></td>
            <td align='right'>   Edição: </td><td><input style="text-align: center;" id="edicao_pub_editar" name="edicao_pub_editar" type="number" min="1000" max="10000" value="<?php echo $linha['edicao_pub']; ?>" style="border: 1px inset" /> <br /></td>
            <td align='right'>   Página: </td><td><input style="text-align: center;" id="pagina_pub_editar" name="pagina_pub_editar" type="number" min="1" max="20" value="<?php echo $linha['pagina_pub']; ?>" style="border: 1px inset" /> <br /></td></tr>
            </table>
            </div>
            <table>
            <tr><td align='right' style="width:158px"><input type="submit" onClick='return CONFIRMAR_EDITAR_DOCUMENTO()' value="Editar" class="buttons buttons-primary buttons-block buttons-large"/></td>
            </form>
            </table>
  • 1

    Your form #CONFIRMAR_EDITAR possesses name?

  • @Lucascosta Sim name='CONFIRMAR_EDITAR' id='name='CONFIRMAR_EDITAR''

  • 1

    If possible, edit the question with the code of that form please.

  • 1

    Also put a part of the HTML of the generated Forms. Another thing, id #CONFIRMAR_EDITAR this in the tag/element <form> why if I’m not mistaken serialize()only works in form.

  • Yes, I will send.

  • 3

    Another possibility is that maybe Voce has several ids CONFIRMAR_EDITAR on the page, since there are several lines, so it may be taking the wrong element, or none, since in the teroria the id should be unique.

  • No. I already looked. kkkk CONFIRMAR_EDITAR

  • @Lucascosta @Neuberoliveira I added the html. As you said in the question, if I pass by $('#id').val()

  • @Neuberoliveira I also noticed that inside this form I had a DatePicker calendar, and it didn’t load when I started working with Ajax and jQuery, I did everything. I inserted in the same file the library and everything, but it didn’t work. I also tried that if I put the scripts within the funcoes.js, after the queries by loading the contents inside the div didn’t work either, I had to pass the script to the same file that was giving back.

  • @Neuberoliveira Believes that <table> in the form was preventing execution? I passed it into the tag and it worked. kkkk

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.