I am trying to use jQuery UI Sortable to re-arrange some items in an HTML list. I’ve got it functioning, but I’m stuck on how to use the data.
I am using Codeigniter and I am passing the order via serial to the update_order method in my Category controller.
I know how I’m going to enter it into the database, but I’m not sure how to use the serial so that I can do it. I’m assuming it’s in a POST variable of some sort, but I don’t know what it is.
The JS:
<script type="text/javascript">
$(document).ready(function() {
$("#order").sortable({
update : function () {
order = $('#order').sortable('serialize');
$.ajax({
url: "<?=base_url().'admin/category/update_order'?>",
type: "POST",
data: order,
success: function(){
alert("success");
}
});
}
});
}
);
</script>
The HTML:
<ul id="order">
<li id="item_1">Item 1</li>
<li id="item_2">Item 2</li>
<li id="item_3">Item 3</li>
<li id="item_4">Item 4</li>
<li id="item_5">Item 5</li>
<li id="item_6">Item 6</li>
</ul>
If doing serialize, do
$this->input->post('item')It’s going to be whatever is in front of the _1, _2, etc in the li tags.