jQuery sortable post data, but there is no data

天大地大妈咪最大 提交于 2020-01-24 10:04:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!