【发布时间】:2015-07-05 04:34:30
【问题描述】:
我想通过覆盖旧文件来更新 json 文件。我可以使用一些 jquery 将数据导出到 json 字符串。数据存储在变量 json_update 中。但我不知道如何将数据发送到 php。
$(function () {
$('#switcher').click(function () {
var json_update = JSON.stringify($('#table-hover').bootstrapTable('getData'));
$.ajax({
type: "POST",
url: "adding2.php",
data: json_update,
contentType: "application/json; charset=utf-8"
dataType: "json",
success: function (data) {
alert("success");
}
});
});
});
这里是 adding2.php 。谢谢你帮助我。
<?php
$data = $_POST['json_update'];
$fileHandler = fopen('work2.json', 'w+');
fwrite('work2.json',$data);
fclose($fileHandler);
?>
【问题讨论】: