caramba
caramba

Reputation: 22490

jQuery sortable post data, but there is no data

Can anyone tell me what I am missing here.

My data seems always to be empty, what am I doing wrong?

$(document).ready(function () {
    $(".nav").sortable({
        connectWith: ".nav",
        axis: 'y',
        update: function (event, ui) {

            var data = $(this).sortable('serialize');   
            // POST to server using $.post or $.ajax
            alert(data);
        }
    }).disableSelection();
});

FIDDLE

Upvotes: 3

Views: 763

Answers (1)

tymeJV
tymeJV

Reputation: 104785

Per the sortable API:

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", "foo-1", and "foo_1" all serialize to "foo[]=1".

Add some ID's with underscores to your li, then your fine.

Demo: http://jsfiddle.net/tymeJV/vzQ2X/4/

Upvotes: 3

Related Questions