【问题标题】:Jquery UI, Draggable/Droppable Append Clone after JsonJquery UI,Json 之后的可拖动/可删除追加克隆
【发布时间】:2012-08-07 03:46:30
【问题描述】:

我一直在玩这行代码试图让它正常运行但没有成功决定在这里发布,希望有人可以提供帮助。

我的问题围绕着使用 DRAGGABLE / DROPPABLE 和 Json 的 JQUERY UI。这是我的代码:

$('.drag').draggable({
        helper: 'clone'
    });
    $(".drop").droppable({
        drop: function(e, ui) {
            var dataString = 'type='+ui.draggable.clone().find('.type').attr('id')+'&update=update';
            $.ajax({
                url: 'phphandler.php',
                type: 'POST',
                data: dataString,
                dataType: 'json',
                success: function(json) {
                    $(this).append(ui.draggable.clone().html(json.Data));
                },
                error: function() {
                    alert(ui.draggable.clone().html);
                }
            });
        }
});

我的 HTML 本质上是:

<div class="drag">Object</div>
<div class="drop"></div>

我要做的几乎就是在成功后将克隆附加到删除或在成功后更改克隆的 html。

注意:我可以毫无问题地在 Ajax 请求之前追加,但成功后无法更改克隆的 HTML。

【问题讨论】:

  • 服务器的响应是什么??
  • code

    基本内容

标签: jquery json jquery-ui draggable droppable


【解决方案1】:

注意函数的作用域

试试

$.ajax({
                url: 'phphandler.php',
                type: 'POST',
                data: dataString,
                dataType: 'json',
                context: this,
                success: function(json) {
                    $(this).append(ui.draggable.clone().html(json.Data));
                },
                error: function() {
                    alert(ui.draggable.clone().html);
                }
            });

var dataString = 'type='+ui.draggable.clone().find('.type').attr('id')+'&update=update';
           var tmp = $(this);
           $.ajax({
                url: 'phphandler.php',
                type: 'POST',
                data: dataString,
                dataType: 'json',
                success: function(json) {
                    tmp.append(ui.draggable.clone().html(json.Data));
                },
                error: function() {
                    alert(ui.draggable.clone().html);
                }
            });

【讨论】:

    猜你喜欢
    • 2018-07-25
    • 2011-07-15
    • 2012-02-06
    • 2018-05-13
    • 2014-06-07
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多