gpt4 book ai didi

php json_decode 和 Jquery Nestable

转载 作者:行者123 更新时间:2023-12-01 04:10:31 25 4
gpt4 key购买 nike

我正在使用 jquery Nestable (http://dbushell.github.io/Nestable/)。

当我更改可嵌套元素的顺序时,我试图从中拦截数据..

$('.dd').nestable().on('change', function() {
var json_text = $('.dd').nestable('serialize');
$.post("/includes/processes/core.php", {
cmd: 'nestable',
table: table,
data: json_text
}, function(response){
alert(response);
});
});

在 core.php 中我已经完成:

$data = $_POST['data'];
$data = json_decode($data, true);
function parseJsonArray($jsonArray, $parentID = 0) {
$return = array();
foreach ($jsonArray as $subArray) {
$returnSubSubArray = array();
if (isset($subArray['children'])) {
$returnSubSubArray = parseJsonArray($subArray['children'], $subArray['id']);
}
$return[] = array('id' => $subArray['id'], 'parentID' => $parentID);
$return = array_merge($return, $returnSubSubArray);
}
return $return;
}

$readbleArray = parseJsonArray($data);

我必须操作这个数组,但我无法继续,因为响应是:

"json_decode() expects parameter 1 to be string, array given in core.php on line (where is "$data = json_decode($data, true;")"

如果我用 json_encode($data) 更改 json_decode($data, true) ,这就是响应:

"Invalid argument supplied for foreach() in core.php on line (where is "foreach ($jsonArray as $subArray);")"

请帮助我..

最佳答案

尝试删除此行,因为 $.post 不执行 json 编码。

$data = json_decode($data, true);

关于php json_decode 和 Jquery Nestable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21242183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com