function send_nested_sets_new_structure(item_id, parent_id, prev_id, next_id){ jQuery.ajax({ type: 'POST', url: 'http://www.onwa-tbay.ca/programs/restructure', data: {node_id: item_id, parent_id: parent_id, prev_id: prev_id, next_id: next_id, authenticity_token: 'AGXbiBVNDWHF1QX19qxXLb36sDnDYcFhSW8EhECpHM0=' }, dataType: 'script', beforeSend: function(xhr){}, error: function(xhr, status, error){alert(error);} });//jQuery.ajax }//fn $(document).ready(function(){ $('ol.sortable').nestedSortable({ disableNesting: 'no-nest', forcePlaceholderSize: true, handle: 'div.handle', helper: 'clone', items: 'li', maxLevels: 3, opacity: .6, placeholder: 'placeholder', revert: 250, tabSize: 25, tolerance: 'pointer', toleranceElement: '> div' }) $('ol.sortable').sortable({ update: function(event, ui){ // ITEM ID item_id = ui.item.attr('id'); if(typeof(item_id) == 'undefined'){ $('#item').html('Have no id'); }else{ $('#item').html(item_id); } // PARENT ID parent_id = ui.item.parent().attr('id'); $('#parent').html(parent_id); // PREV ID prev_id = ui.item.prev().attr('id'); if(typeof(prev_id) == 'undefined'){ $('#prev').html('It is first!'); }else{ $('#prev').html(prev_id); } // NEXT ID next_id = ui.item.next().attr('id'); if(typeof(next_id) == 'undefined'){ $('#next').html('It is last!'); }else{ $('#next').html(next_id); } send_nested_sets_new_structure(item_id, parent_id, prev_id, next_id); } }); });