Jquery UI,可拖动/可删除在 JSON 之后追加克隆



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

我的问题围绕着使用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。

注意函数的作用域

尝试

$.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);
                }
            });

最新更新