Saving Sortable Order Changes in jQuery UI to a Database
Incorporating jQuery UI's Sortable feature allows users to reorder elements. To save these changes to a database, follow these steps:
Implement Sortable:
Capture Order Changes:
Serialize Data:
AJAX Request:
Database Update:
Example Code:
$('#element').sortable({ axis: 'y', update: function (event, ui) { var data = $(this).sortable('serialize'); $.ajax({ data: data, type: 'POST', url: '/your/url/here' }); } });
Implementation Details:
Example Server-Side Script (PHP):
$i = 0; foreach ($_POST['item'] as $value) { // Execute statement: // UPDATE [Table] SET [Position] = $i WHERE [EntityId] = $value $i++; }
The above is the detailed content of How Can I Save jQuery UI Sortable Changes to a Database?. For more information, please follow other related articles on the PHP Chinese website!