0
Hello. I need to save some html form information in php but without reloading the page. I searched several tutorials and video ajax class but I’m doing something very wrong or I don’t really 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?
}
});
});
});
Php file:
<?php
if(isset($_POST["acao"])){
$nome = $_POST["nome"];
var_dump($nome);
}
Why don’t you send something in php? what am I doing wrong?
Any error appears in the browser console?
– Guilherme Nascimento
You must summon this serialize with
()
... that is to say:$("#form").serialize()
– Sergio
Your Hidden input 'action' has no value set and I saw no place you seven some value, set one before sending
– Mateus Veloso