ui.draggable不会被推入数组并使用join和push以逗号显示

时间:2012-11-18 19:29:05

标签: php jquery-ui join push

我希望可拖动div的id在警告按钮中显示为逗号分隔列表,如果它们被放入droppable_box中。相反,每个拖动的div都会一个接一个地发出警报,而不是列表。

<script type="text/javascript">
    $(document).ready(function(){
    $( "#draggable1" ).draggable({ grid: [ 20,20 ] });
    $( "#draggable2" ).draggable({ grid: [ 20,20 ] });
     $( "#draggable3" ).draggable({ grid: [ 20,20 ] });

        $( "#droppable_box" ).droppable({

            drop: function( event, ui ) {
            var currentId = $(ui.draggable).attr('id');

            var stuff = [];
            $.each($(ui.draggable), function(i,e) {
                stuff.push(e.id);
            });

            var energy = stuff.join(", ");

            var data = "X-Requested-With=XMLHttpRequest";

    $('#myId').click(function(){

        $.post (
            "process.php",
            data,
            function(data)
            {
            alert(energy);

            },
            'html'
            );
         });

        }
        });
    });
</script>   

在html中有3个可拖动的div

<div id="draggable1" class="draggable_meal"></div>
<div id="draggable2" class="draggable_meal"></div>
<div id="draggable3" class="draggable_meal"></div>

我稍微更改了jquery并将其发布为here

您可以查看视图来源。感谢。

在process.php中,它给了我1到3个数组,具体取决于我拖动的div数。我想使用

将$ _REQUEST对象推送到数组中
foreach ($_REQUEST as $key => $value) {
            array_push($stack,$value);
          }
print_r($stack);

但它给了我1到3个数组,每个数组的键为零。如何从例如3个拖动的div中获取一个数组?

0 个答案:

没有答案