Jquery UI sortable, write the command in a MySql database


I'm currently using JQuery UI Dragabble, Droppable and sortable. I have two div sections at top and bottom of my php file were i'm dragging and dropping contents from bottom to top div sections.

In top div section i'm performing Sortable JQUery opertions my next requirment is when i perform sorting operation in top section its order should be automatically updated in my MYSQL DB i gotta stuck like how to pass the sorted order to my MySQL db via ajax and php file. Can somebody suggest some help in Achieving it!


Html/PHP code

<div class="drop_list">
        <ol id="sortable" style="list-style:decimal;"></ol>
    <div class="sort_list">
    <ul id="draggable">
                <li data-id='article_<?php echo $i;?>' class="draggable_li qitem" >
                    <div class="main_div">
                        <div class="secondary_div">
                            <div class="form_div">
                                    <input style="width:15px;" type="checkbox" class="hello"/>
                            <label class="item_div">
                                <span class="item">Item = <?php echo $i; ?></span>
                        <button class="hello btn btn-success add_top">
                            Add to Top Stories
                        <span class="AH_section" style="display:none;float:right;">
                            <input type="checkbox"/>Home Section
                            <input type="checkbox"/>App Home Section

JQuery code

$(document).ready(function() {

            revert: true,
            refreshPositions: true ,
            helper : 'clone',
            cursor: "move",
            delay: 1,
            tolerance: 'pointer',
            revert: 50
                var data = $(this).sortable('serialize');

        $("ol li").disableSelection();

        $(".sort_list li").draggable({
            //containment : "#container",
            helper : 'clone',
            refreshPositions: true ,
            revert : 'invalid',

        $(".drop_list ol").droppable({
            //hoverClass : 'ui-state-highlight',
            greedy: true,
            refreshPositions: true,
            drop : function(ev, ui)
                if($(this)[0].id === "sortable")
                    //$(ui.draggable).draggable( 'disable' ); //this will not append dragged list at top of the container
                    ui.draggable.draggable( 'disable' ).closest('li').prependTo(ui.draggable.closest('ul')); //this will append dragged list at top of the container
                    return true;

change data-id='article_<?php echo $i;?>' to id='<?php echo $i;?>'

add this to your sortable(),

update: function (event, ui) {
         var serial=$(this).sortable('serialize');

so here on update, you are calling save_sortable() function, from ajax , update your db in the order returned from sortable()

function save_sortable(serial)
         url: "path to your file to update in db.",
         type: 'POST',
         data: serial,
         success: function (data) {