Ajax take form data to compose in the url

Asked

Viewed 141 times

0

I have an ajax call that needs to take all the form fields and post to a URL. My code is like this:

<script>
        $(document).ready(function() {     
            $('#somebutton').click(function(event) {  
                var valorAplicado=$('#valorAplicado').val();
                $('#somediv').html('');
                $('#somediv').html('<center><img src="images/aguarde.gif" width="60" height="60" alt="Aguarde" class="loading"></center>');

            $.get('http://www.endereco.com.br/Simulacao2',$('form_t').serialize(),function(responseText) { 

            if(responseText) { 

            $('#somediv').html('<center><img src="images/aguarde.gif" width="60" height="60" alt="Aguarde" class="loading"></center>');
                $('#somediv').html("<html>" +responseText+ "</html>" ); 
                    window.scrollTo(5000,document.body.scrollHeight);
                }else{
                     //alert("Error");
                 }
                    //$('#somediv').html(responseText); 
                });
            });
        });

But you are not taking the form fields, follow form code:

  <form id="form_t" name="form_t" class="col s12" method="post">
<div class="row">
<div class="input-field col s12">
  <input id="aplicacao" class="validate" type="text" value="1000">
  <label class="active" for="aplicacao">Aplicação:</label>
</div>
<div class="input-field col s12">
  <input id="aplicacao" class="validate" type="text" value="24">
  <label class="active" for="aplicacao">Período (meses):</label>
</div>

  • 1

    There’s no missing one # here: $('form_t').serialize()?

1 answer

0

I figured you need to have the name="nome of input" to pick up the $('#form_t').serialize()

Browser other questions tagged

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