0
I started studying Javascript and Jquery. I was doing a test to display on the screen what was sent via Form, but it is sending value only from a field, someone would be able to help me?!
Here’s 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 php just for testing (Insert.php):
<?php
var_dump($name = $_POST['nome']);
$last_name = $_POST['sobrenome'];
Thanks in advance!
Your code looks ok. You can do Alert, or console.log from
valor
to see what’s there? and in PHP you’re just doingvar_dump
of one of the fields. It would be better to dovar_dump($_POST);
. What gives you that?– Sergio