I have 4 input and using Ajax to send data, to a php file: Now i am curious how to append this data to the json file?
<input type="text" id="name">
<input type="text" id="surname">
<input type="text" id="mobile">
<input type="text" id="email">
<script>
var name = $("#name").val();
var surname = $("#surname").val();
var mobile = $("#mobile").val();
var email = $("#email").val();
$.ajax({type:"POST",
url:"wjson.php",
data:"name="+nombre+"&surname="+surname+"&mobile="+mobile+"&email="+email,
success:function(data) {
}
});
JSON file: (people.json)
{
"1":
{
"Name" : "Jhon",
"Surname" : "Kenneth",
"mobile" : 329129293,
"email" : "[email protected]"
},
"2":
{
"Name" : "Thor",
"Surname" : "zvalk",
"mobile" : 349229293,
"email" : "[email protected]"
}
}
wjson.php file :
<?php
$nane = $_POST['name'];
$surname =$_POST['surname'];
$mobile = $_POST['mobile'];
$email =$_POST['email'];
$str_datos = file_get_contents("people.json")
//add new data to people.json
?>
by the way people.json file is in my server