1

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 :-)

1
  • 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! Commented Mar 15, 2015 at 12:41

1 Answer 1

1
<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 ..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.