我有 4 个输入,由 Ajax 4 数据发送到一个 php 文件:
如何加载 json 文件,然后在 php 中添加新数据?
<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 文件:(people.json)
{
"1":
{
"Name" : "Jhon",
"Surname" : "Kenneth",
"mobile" : 329129293,
"email" : "jhon@gmail.com"
},
"2":
{
"Name" : "Thor",
"Surname" : "zvalk",
"mobile" : 349229293,
"email" : "thor@gmail.com"
}
}
wjson.php 文件:
<?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
?>
顺便说一下 people.json 文件在我的服务器中