I read a few questions on Stackoverflow that recommend using serialize() and toArray with sortable() to prepare the data for insertion in a database. However, when I try to pass them to sortable('toArray') or sortable('serialize'), it breaks the code i.e. the list is no longer sortable. Here's a fiddle
http://jsfiddle.net/mjmitche/sTzCS/16/
Does anyone know what I'm doing wrong?
<ul id="sortlist">
<li id="Vancouver">Vancouver</li>
<li id="Toronto">Toronto</li>
<li id="Montreal">Montreal</li>
<li id="Ottawa">Ottawa</li>
<li id="Calgary">Calgary</li>
<li id="Edmonton">Edmonton</li>
<li id="Winnipeg">Winnipeg</li>
</ul>
JavaScript
// also tried $('#sortlist').sortable('serialize);
var result = $('#sortlist').sortable("toArray");
alert(result);
This is how to do it
$("#sortlist").sortable({stop: function(event, ui) {
result = $("#sortlist").sortable("toArray");
alert(result.length);
}});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With