0

私はこのコード行をいじって、正しく機能させようとしましたが、成功せずにここに投稿することにしました。誰かが助けてくれることを願っています。

私の問題は、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 を変更することはできません。

4

1 に答える 1

0

関数の範囲に注意してください

試す

$.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);
                }
            });
于 2012-08-07T05:02:14.003 に答える