Jquery sortable('serialize')

I finally got the answer! You need to make the UL sortable first before calling the serialize method on it:

var sortableLinks = $("#category_links_list_3");
$(sortableLinks).sortable();
var linkOrderData = $(sortableLinks).sortable('serialize');

This time linkOrderData contains category_link[]=8&category_link[]=9


If serialize returns an empty string, make sure the id attributes include an underscore. They must be in the form: "set_number" For example, a 3 element list with id attributes foo_1, foo_5, foo_2 will serialize to foo[]=1&foo[]=5&foo[]=2. You can use an underscore, equal sign or hyphen to separate the set and number. For example foo=1 or foo-1 or foo_1 all serialize to foo[]=1.

Above one is a example. that i used it. That is why I saw 2 you.

http://jqueryui.com/demos/sortable/#method-serialize

it migth be help you.


var formStr = $('#container').serialize()

Added: That will work for form elements. You could also roll your own serialize like so:

function serializeList(container)
{
  var str = ''
  var n = 0
  var els = container.find('li')
  for (var i = 0; i < els.length; ++i) {
    var el = els[i]
    var p = el.id.lastIndexOf('_')
    if (p != -1) {
      if (str != '') str = str + '&'
      str = str + el.id.substring(0, p) + '[]=' + (n + 1)
      ++n
    }
  }
  return str
}

alert(serializeList($('#container')))