javascript - jQuery 可排序发布数据,但没有数据

标签 javascript jquery jquery-ui

谁能告诉我我在这里缺少什么。

我的数据似乎总是空的,我做错了什么?

$(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

最佳答案

根据 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".

在您的 li 中添加一些带下划线的 ID,然后就可以了。

演示:http://jsfiddle.net/tymeJV/vzQ2X/4/

关于javascript - jQuery 可排序发布数据,但没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18902974/

相关文章:

javascript - 有没有办法将这两个x轴合并为一个轴?

javascript - 在 ReactJS 呈现的内容中延迟加载图像、视频和 iframe

javascript - Jquery 选项卡按条件打开

jQuery UI 选项卡 - SlideToggle?

javascript - 通过 window.open(url ,"_self") 打开页面从 url 获取参数值?

javascript - NoFlo graph.json/graph.fbp 转 JavaScript 文件

javascript - 添加新 HTML 项目后丢失事件触发

javascript - 尝试使用 jQuery 从 DOM 中删除元素

javascript - 具有多个可见图像的无限画廊

jquery-ui - jQuery UI Accordion 的部分包含在DIV中