我正在尝试通过php调用更新json文件。 在我的控制台中,参数不为空,但是当我检索json文件时,该值不存在。
保存功能如下:
Handsontable.Dom.addEvent(save, 'click', function() {
var dataarray = JSON.stringify(hot.getData());
ajax ('json/projectupdate.php', 'POST', {"infos:":dataarray}, function (res) {
console.log (dataarray)
});
在控制台中,结果如下:
[["test1","","gep2","",null,null,null,null,null],["","test1","","gep2",null,null,null,null,null],["dag","","test1","","gep2",null,null,null,null],["","dag","","test1",null,"gep2",null,null,null],["","","dag","","test1",null,"gep2",null,null],["","","","dag",null,"test1",null,"gep2",null],[null,null,null,null,"dag",null,"test1",null,null],[null,null,null,null,null,"dag",null,"test1",null],[null,null,null,null,null,null,"dag",null,"test1"],[null,null,null,null,null,null,null,"dag",null],[null,null,null,null,null,null,null,null,null]]
这是我在表格中写的实际内容。
然后我传递(或者至少我尝试传递)我的var到我的(projectupdate.php
)php文件:
<?php
$myFile = "project.json";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $_POST['infos'];
$stringData1='{ "data":'$stringData'}';
fwrite($fh, $stringData1);
fclose($fh);
?>
结果是projectupdate.php
写在project.json
"{ "data":}"
上,但没有其他内容。
我肯定做错了。