weixin_33735077 2015-04-26 21:13 采纳率: 0%
浏览 71

用PHP创建一个json文件

I want to update the json file by overwriting the old one. I can export the data to a json string by using some jquery. And the data is stored in the variable json_update . But I don't know how to send the data to 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");

             }
         });
    });
});     

And here is the adding2.php . Thanks for helping me.

<?php
$data = $_POST['json_update'];
$fileHandler = fopen('work2.json', 'w+');
fwrite('work2.json',$data);
fclose($fileHandler);
?>
  • 写回答

2条回答 默认 最新

  • weixin_33712987 2015-04-26 21:17
    关注

    The data you send from the client side (the value of json_update) is stored in $_POST, so just change $data = $_POST['json_update']; to $data = $_POST;.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度