Hello. I need to save some information from the html form in php but without reloading the page. I tried several ajax tutorials and video lessons but I'm doing something very wrong or I really did not understand anything about how ajax works. My html:
<form method='post' id="form">
Nome: <input name="nome" id="nome" type="text"/>
<input type="hidden" name="acao" />
<input type="submit" value="Enva" id="submit"/>
</form>
Javascript:
$(document).ready(function(){
$('#submit').click(function(event){
event.preventDefault();
$.ajax({
type: 'POST',
data: $("#form").serialize,
url: 'teste.php',
success:function(data) {
// deu certo?
}
});
});
});
File php:
<?php
if(isset($_POST["acao"])){
$nome = $_POST["nome"];
var_dump($nome);
}
Why do not you send anything in php? What am I doing wrong?