我想更新数据库中列表的顺序。这是可排序的js函数
$(function() {
$('#sortable').sortable({
axis: 'y',
opacity: 0.7,
handle: 'span',
update: function(event, ui) {
var list_sortable = $(this).sortable('toArray').toString();
$.ajax({
url: "/lists/update_order",
type: 'POST',
data: {list_order:list_sortable},
success: function(data) {
}
});
}
});
});
这是视图
<ul class="gift-list ui-sortable" id="sortable">
foreach ($q->result() as $key => $row) {
echo "<li class='list_container'>" .$row->listTitle;." </li>" ?>
<?} ?>
</ul>
每当我尝试通过拖动来更改列表的顺序时,即使我在控制器中有它,我也会向http://localhost/lists/update_order收到404错误
public function update_order(){
echo "sorted";
}
答案 0 :(得分:0)
$.ajax({
url: "<?php echo base_url(); ?>index.php/lists/update_order",
type: 'POST',
data: {
list_order: list_sortable
},
success: function(data) {}
});
使用base_url()在您的ajex网址中添加基本网址功能