Sortable.serialize

The Sortable object also provides a function to serialize the Sortable in a format suitable for HTTP GET or POST requests. This can be used to submit the order of the Sortable via an Ajax call:

 

Availability

 

script.aculo.us V1.0 and later.

 

Syntax

 

Sortable.serialize('id_of_container',[options]);

 

Options

 

Option

Since

Default

Description

tag

V1.0

tag originally used on Sortable.create

Sets the kind of tag (of the child elements of the container) that will be serialized.

name

V1.0

id of container        

Sets the name of the key that will be used to create the key/value pairs for serializing in HTTP GET/POST format (that is, key[]=value&key[]=value …)

 

Example

 

var userTopTen = Sortable.serialize('top10');

// userTopTen now contains key[]=value pairs seperated by &

 

new Ajax.Request('/users/mytop10/saveorder', {parameters: userTopTen});

 

Notes

 

For this to work, the elements contained in your Sortable must have id attributes in the following form:

 

<li id="image_1">Something</li>

 

You can tweak this by modifying the format parameter in the Sortable.create call