简体   繁体   中英

drag and drop with jquery and php

hy, i have a php array with the name of some images! i list all the images use this:

$files = $_SESSION['files'];
$imgid = $_POST['id'];
if ($files){
        foreach($files as $image ):
            print '<li id="liupimages">'."\n";
                print '<a href="uploads/'.$image.'"><img id="'.$imgid.'" alt="'.$image.'" src="uploads/'.$image.'"></a>'."\n";
            print "</li>\n";
        endforeach;
    print <<<JS
<script>
$(".thumbs li a").click(function(){
    var largePath = $(this).attr("href");
    $('.thumbs li').removeClass('thumbac');
    $(this).parent().addClass('thumbac');
    $("#largeImg").hide()
                  .attr({ src: largePath })
                  .load(function() {
                       $(this).show();
                   });
    return false;
});

</script>
JS;
} 

i use jquery-ui to drag and drop images using this function:

$(function() {
    $("#upimagesQueue").sortable({ opacity: 0.6, cursor: 'move', update: function() {
    //??                                                         
    }                                 
    });
});

after i drag and drop one image i want to be able to update the php array to! how to do this?

Use ajax:

$.get("re-arrange.php", { 'myArray[]': ['file1', 'file2']} );

http://api.jquery.com/jQuery.get/

Don't use jQuery use dom-drag it's much better and more functional.

Add this code:

<script type="text/javascript" src="http://www.dynamicdrive.com/dynamicindex11/domdrag/dom-drag.js"></script>
<script type="text/javascript">
Drag.init(document.getElementById("exampleid")); //sets the id to look for to make object draggable
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM