问题
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
回答1:
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/
来源:https://stackoverflow.com/questions/18902974/jquery-sortable-post-data-but-there-is-no-data