Serielize() jquery does not save variables

Asked

Viewed 27 times

0

I’m not able to record the variables with jquery serialize(), esotu doing so, what would be the problem?

//Executa em cada form:
$('.formAjax').on("submit",function() {

    // Pegar o ID do formulário para depois:
    //Captura o elemento que sofreu o evento de "submit"
    const formDetails = $(this);

    var formID=formDetails.data("formid");

    //Remove a palavra quitar_ e deixa somente "debitoX"
 $('.resultado_empresa_selecionada_'+formID).html('<img src="imagens/Rolling-1s-30px.gif">');

$.ajax({
     type: "post",
     url: "add_email.php",
     data: formDetails.serialize(),
     success: function(data) {
         //Faz alguma coisa

         $('.resultado_empresa_selecionada_'+formID).html(data); 


$('.resultado_empresa_selecionada_'+formID).fadeIn('slow').html(data);

     }
 });
    return false;
});

Html

<form id="selecionar_empresa_form_273" class="formAjax formAjax2" data-formid="273" method="post" enctype="multipart/form-data">
<div class="resultado_empresa_selecionada_273">
<input type="hidden" name="id_usuario" id="id_usuario" value="273">


<select id="atendente" class="form-control atendente" name="atendente" required="">
    <option value="" selected="">Selecine um Atendente</option>
    <option value="[email protected]">Central de Vendas</option>
    <option value="[email protected]">Claudia</option>
    <option value="[email protected]">Céia</option>
    <option value="[email protected]">Claudia Lima</option>
    <option value="[email protected]">Neide</option>
    </select>


<button type="submit" class="botao_add">Adicionar atendente</button>
</div>
</form>
  • what generates in the formDetails.serialize()?

  • would be generated the varaiaveis of the formmulario

  • would be here $('.resultado_empresa_select_'+formID). html(date); but it doesn’t work

  • right but what doesn’t work? formDetails.serialize() returns something, gives error??

1 answer

0

Try the following:

Change

formDetails.serialize();

for

formDetails.toJSON();

and treat the controller to receive the JSON file.

  • need it to be with the serialize(); thanks for the attention friend

  • For nothing, I’m at your disposal!

Browser other questions tagged

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