Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to create an nestable list which I can reorder by drag and drop and are doing very well up til now, thank yo very much ;-), but...

Everything is working as it should but I want to be able to save tor order into the db through php when I drop an item but am not sure how to do so?

When I drop an item I get an array of objects like this:

[Object, Object, Object, Object, Object, Object, Object]

Each object and item and a itemId:

<li data-item="<?=$row['name']?>" data-item-id="<?=$row['fk_module_id']?>">

How do I pass this to php through ajax and how do I open the objects in the php script?

Here is the jQuery that handles the dragDrop part:

$("#modules-active").on('nestable-stop', function(ev)
{
    var serialized = $(this).data('nestable').serialize(),
    str = '';

    console.log( serialized );
    console.log( $(this).data('nestable').list() );

    $.post( "savelist.php", { list: serialized }).done(function( data ) { 

    });

});

To recap: How do I pass this correctly to php and how do I open and save it on the php page?

any help is appreciated and thanks in advance :-)

share|improve this question
    
serialize() can only act on a jQuery object that has selected individual form controls, such as <input>, <textarea>, and <select> and not on list items! –  LShetty Mar 15 at 12:41

1 Answer 1

up vote 1 down vote accepted
<li class='data' data-item="<?=$row['name']?>" data-item-id="<?=$row['fk_module_id']?>">


jQuery(document).ready(function($){

    url = " Your php file url/savelist.php";
    var allVals = [];
    $('.btn').click(function(){

        $('.data').each(function() {
            allVals.push($(this).val());
        });
        $.post(url,{ array : allVals }, function(response,status){

            if(status == 'success'){

                //ur stuffs
                return status;
            }
        })
    })

})

it may help u ..

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.