I'm using a neat sort plugin for jQuery, HTML5 Sortable http://farhadi.ir/projects/html5sortable/ but haven't found an ideal way of serialize data to send as an AJAX POST request (to update DB).
HTML
<ul class="sortable">
<li data-id="1">One</li>
<li data-id="2">Two</li>
<li data-id="3">Three</li>
<li data-id="4">Four</li>
<li data-id="5">Five</li>
</ul>
jQuery
$('ul.sortable').sortable().bind('sortupdate', function()
{
var data = ??; // serialize all data-id's ... this is my problem
$.post('/sortupdate.php',data,function(){ // PHP script sets new order in DB
alert('updated');
});
});
So what I want to happen is that when I drag an LI item to a new position then the sortupdate event should trigger the function and send the new order of data-id attribute values. My current idea is to loop through the LI's and add attribute values to an array. Is there any smarter way of doing this, or, what is the most efficient way of doing the loop? (I'm mostly a backend guy you know). Thanks!