JQuery: What to do with the list that sortable(‘serialize’) returns


With jQuery I'm retrieving positions of a sortable list using 'serialize', like this:

var order = $('ul').sortable('serialize');

The variable 'order' then receives the following:


Now how can I use this data in an ajax call?

This is how I plan to do it, but it's ugly and I can't change the parameter name 'id':


Maybe I need to unserialize, then implode the variable 'order' and assign it to just one parameter?

I don't have a problem with the server side code, but I have a problem with the jQuery client site code. The question is, where do I place the 'order' variable in the script?

In the example I gave I added it as a query string:


But I would like to pass it as a parameter, just like the action parameter. The following doesn't work, it returns a syntax error:


Best Answer

Found it! I needed to add the option key:'string' which changes the variable name to 'string' instead of 'id'.

var order = $('#projects ul').sortable('serialize',{key:'string'});