JQuery is only displaying an input value with .serialize () [closed]

0

I started studying JavaScript and JQuery. I was doing a test to display on the screen what was sent via Form, but you are only sending value from a field, could anyone help me?!

Here is the HTML with the script:

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<form name="frm" id="frm" method="POST" action="">
   <input type="text" name="nome" id="nome" value="" />
   <input type="text" name="sobrenome" id="sobrenome" value="" />
   <input type="submit" name="enviar" id="enviar" value="Enviar" />
</form>
<div id="exibir_valor"></div>
<script>
   $("#enviar").click(function(e) {
     e.preventDefault();
     var valor = $("#frm").serialize();
     $.ajax({
       action: $(this),
       type:'POST',
       data: valor,
       url:'insert.php',
       success:function(data) {
         $( "#exibir_valor" ).html(data);
       }
     });
   });
</script>

and here is the php just to test (insert.php):

<?php
  var_dump($name = $_POST['nome']);
  $last_name = $_POST['sobrenome'];

Thank you in advance!

    
asked by anonymous 26.09.2014 / 16:20

2 answers

1

I've already tried the insert.php file so, for me the js file is correct

<?php
  var_dump($name = $_POST['nome']);
  var_dump($last_name = $_POST['sobrenome']);
    
26.09.2014 / 16:25
1

Jquery is working correctly (see jsfiddle ), but in PHP you are giving var_dump only in $_POST['nome'] , to see all do so:

PHP:

var_dump($_POST);

or so:

print_r($_POST);
    
26.09.2014 / 16:49