Imaulle Posted May 10, 2011 Share Posted May 10, 2011 Hello, I'm trying to do what this guy does here - http://www.hdeya.com/blog/2009/05/sorting-items-on-the-fly-ajax-using-jquery-ui-sortable-php-mysql/ but it's not working for me It seems $_POST['p_headerimages'] is always empty Here is my code: <script> $(document).ready(function(){ $("#SlideshowOne").sortable({ update: function(){ serial=$('#SlideshowOne').sortable('serialize'); $.ajax({ url: "sort_slideshow1.php", type:"post", data:serial, error:function(){ alert("theres an error with AJAX") } }) } }); </script> <ul id="SlideshowOne"> <?php $result = mysql_query("SELECT filename FROM p_headerimages ORDER BY ordernum") or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo '<li id="p_headerimages_'.$row['ordernum'].'" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span> '. $row['filename'] .' </li>'; } ?> </ul> <?php require_once("../../../wp-config.php"); $p_headerimages = $_POST['p_headerimages']; for ($i = 0; $i < count($p_headerimages); $i++) { mysql_query("UPDATE p_headerimages SET ordernum=" . $i . " WHERE filename=' ".$p_headerimages[$i]."'") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235977-jquery-ui-sortable-ajax-post/ Share on other sites More sharing options...
trq Posted May 10, 2011 Share Posted May 10, 2011 Where have you defined serial? Quote Link to comment https://forums.phpfreaks.com/topic/235977-jquery-ui-sortable-ajax-post/#findComment-1213274 Share on other sites More sharing options...
Imaulle Posted May 10, 2011 Author Share Posted May 10, 2011 I figured it out! my database did not have an ID so the sorting was not being done correctly Quote Link to comment https://forums.phpfreaks.com/topic/235977-jquery-ui-sortable-ajax-post/#findComment-1213332 Share on other sites More sharing options...
Imaulle Posted May 11, 2011 Author Share Posted May 11, 2011 okay new issue I'm trying to figure out now... How would I have the .click() function also send some data to a php script that I can use to delete the li from the database that was just clicked Here is my current javascript $(function() { $('#SlideshowOne').sortable({ update: function(event, ui) { var data = $(this).sortable("serialize"); $.post("sort_slideshow1.php", data); } }); $('#SlideshowOne a').click(function() { $(this).parent('li').fadeOut("slow", function() { $(this).remove(); }); }); $("#SlideshowOne").disableSelection(); }); Quote Link to comment https://forums.phpfreaks.com/topic/235977-jquery-ui-sortable-ajax-post/#findComment-1213712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.