I am using this code to save my JQuery UI sort order:
$(function() {
$('#sortable').sortable({
update: function (event, ui) {
var data = $(this).sortable('serialize');
$.ajax({
data: data,
type: 'POST',
url: '/sort.php'
});
}
});
$( "#sortable" ).disableSelection();
});
This produces an array of numbers. Let's say I also want to save keys with the numbers, based on tags in my list items.
So for example a sorted list such as:
<ul id='sortable'>
<li id='item-3' name='special'><image src='special.jpg'></li>
<li id='item-1' name='normal'><image src='normal.jpg'></li>
<li id='item-2' name='extraordinary'><image src='extraordinary.jpg'></li>
</ul>
Would produce this array in PHP:
$item['special'] = 3;
$item['normal'] = 1;
$item['extraordinary'] = 2;
I know how to access the tags with JQuery but not how to serialize these into an array to pass to my PHP script along with the sorted numbers. Help!