【发布时间】:2015-02-04 03:53:27
【问题描述】:
所以我有 2 个盒子。在左侧,我有一个从数据库中提取的项目列表,我可以将其拖放到右侧。这很好用。我这辈子都不知道如何让它发布右侧列表的数据,我想我已经尝试了谷歌本周提供的所有示例。
当我执行 print_r($_POST);在这个提交的页面上,我得到了 Array ( ),其中没有任何内容。它似乎没有抓取 ID 并对其进行序列化。
有没有人有这方面的经验看看我遗漏了什么?
<script>
$(function() {
$( "ul.droptrue" ).sortable({
connectWith: "ul"
});
$( "ul.dropfalse" ).sortable({
connectWith: "ul",
dropOnEmpty: true
});
$( "#sortable1, #sortable2" ).disableSelection();
});
$( "#sortable2" ).sortable({
axis: 'y',
handle : '.handle',
update: function (event, ui) {
var data = $(this).sortable('serialize');
console.log(data);
// POST to server using $.post or $.ajax
$.ajax({
data: data,
type: 'POST',
url: 'setlists-edit-process.php'
});
}
});
</script>
<ul id="sortable1" class="droptrue">
<?php
$_GET['setlist_id'];
$sql = "SELECT material_id, material_name FROM material WHERE user_id=$session_id";
$result = mysqli_query($conn, $sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
while($row = mysqli_fetch_array($result))
{
echo "<li id=" . $row['material_id'] . ">" . $row['material_id'] . " | " . $row['material_name'] . "</li>";
}
?>
</ul>
<ul id="sortable2" class="dropfalse">
</ul>
【问题讨论】:
-
你的 console.log(data) 显示什么?
-
setlists-edit.php?setlist_id=8:16 Uncaught SyntaxError: Unexpected token & jquery.flot.js:711 Uncaught Invalid dimensions for plot, width = null, height = null
-
我还以为是参数字符串?
-
摆脱了其中一个错误。 console.log 现在显示:function log() { [native code] }
-
Check out serialize 另请注意,
<li>元素的 id 必须包含下划线。
标签: php jquery jquery-ui jquery-ui-sortable