I'm trying to serialize a form and send the serialized data with ajax using POST method ..
index.php
<form id ="form" class = "form">
<input type = "text" name = "name" />
<input type = "number" name = "age" />
<input type = "number" name = "id" />
<input type = "submit" name = "submit"><br/>
</form>
<p id = "result"></p>
Jquery snippets
<script>
$(document).ready(function(){
$("#form").submit(function(){
var data = $("#form").serialize();
insertStudent(data);
return false ;
});
function insertStudent(data){
$.post("process.php" , { data : data} , function(str){
$("#result").html(str);
});
}
});
</script>
process.php
$ret = $_POST["data"];
echo "<br />".$ret["name"];
And now , the result is :
Notice: Undefined index: name in C:\xampp\htdocs\try.php on line 3
When i tried to echo $_POST["data"] the result is :
name=Ahmed&age=111&id=222
how can i use every name individually such as : $_POST["name"] ... $_POST["age"] ... $_POST["id"] ?