【问题标题】:Multiple jQuery Sortable Lists updating MySQL database with AJAX使用 AJAX 更新 MySQL 数据库的多个 jQuery 可排序列表
【发布时间】:2012-04-18 17:51:29
【问题描述】:

我有多个从 MySQL 中的列表动态生成的可排序列表。每个列表的 id 使用数据库中的部分 id 附加。排序后,数据被序列化并发送到 sort_order_piece.php 以运行 MySQL 查询以更新记录的顺序,一切正常。不起作用的是我编写以下 jQuery 来说明每个列表的动态生成的 id 的方式:

$(".sortme_piece").each(
    function(e) {
        num = e+1;
        $('#sortme_piece_'+num).sortable({
            placeholder: "ui-state-highlight",
            update : function () {
                serial = $('#sortme_piece_'+num).sortable('serialize');
                alert(serial);
                $.ajax({
                    url: "sort_order_piece.php",
                    type: "post",
                    data: serial,
                    beforeSend: function(){$('#updated').html('updating');},
                    success: function(data){$('#updated').html(data);},
                    error: function(){alert("theres an error with AJAX");}

                });
            }
        });
    });

这一行似乎是个麻烦:

serial = $('#sortme_piece_'+num).sortable('serialize');

当我在警告框中查看变量时,它是空白的。如果我删除附加的 'num' 并添加一个与列表 id 之一相对应的实际数字,它就可以正常工作。

我到底做错了什么?我只是无法确定它。

帮助,谢谢!!!

【问题讨论】:

    标签: php jquery ajax jquery-ui-sortable


    【解决方案1】:

    我变了

    serial = $('#sortme_piece_'+num).sortable('serialize');
    

    serial = $(this).sortable('serialize');
    

    然后就解决了。

    【讨论】:

      猜你喜欢
      • 2013-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 2013-05-27
      • 2013-03-10
      • 1970-01-01
      相关资源
      最近更新 更多