我已将jQuery可排序插件放入从数据库中拉出的客户的foreach循环中。我现在正在尝试将定位插入到数据库表中。我对jQuery和AJAX的了解非常有限,因此我发现这特别困难。任何建议将不胜感激。
>>> myround(0.5)
1.0
>>> myround(1.5)
2.0
>>> myround(-0.5)
-1.0
>>> myround(-1.5)
-2.0
>>> myround(1)
1.0
使用sql函数保存文件:
$customers_set = select_customers();
while($customer = mysqli_fetch_assoc($customers_set)){
$customers[] = $customer;
}
?>
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<ul id="sortable">
<?php
foreach($customers as $customer){
?>
<li id="item-<?php echo $customer['id']; ?>"><?php echo $customer['customer_name'] . ' - ' . $customer['position']; ?></li>
<?php } ?>
</ul>Query string: <span></span>
<script>
$(document).ready(function () {
$('ul').sortable({
axis: 'y',
stop: function (event, ui) {
var data = $(this).sortable('serialize');
$.ajax({
data: oData,
type: 'POST',
url: '<?php echo doc_root('/test_save.php'); ?>'
});
}
});
});
</script>