Neil
Neil

Reputation: 794

JQuery Sortable\Serialize issue

I have a document that uses PHP to generate a list from a DB

$q = "SELECT * FROM display ORDER BY diplay_order ASC";
$r = @mysqli_query ($dbc, $q);

echo "<ul id='categoryorder'>";

while ($item = mysqli_fetch_array($r)) {

echo "<li><div id='" . $item['ad_type'] . "_" . $item['unique_id'] . "'>
      <form name='remove' action='saveable.php' method='get'>
      <input type='submit' value='remove' />
      <input type='hidden' name='id' value='" . $item['unique_id'] . "'>
      </form>" .$item['unique_id'] . "</div></li>";     
}

echo "</ul>";

I have then made these sortable which works fine but I can't get the serialize to work and it just creates an empty array.

$(document).ready(function() {                             
   $('ul#categoryorder').sortable({ 
    update: function() {
        var order = $("ul#categoryorder").sortable("serialize");
        alert(order);
    }                                         
});
});

Then the alert box just comes up empty. I am very new to this and any help would be much appreciated.

Upvotes: 0

Views: 399

Answers (1)

Muthu Kumaran
Muthu Kumaran

Reputation: 17910

You need to add id to <li> tag. Change this part of PHP code,

echo "<li id='" . $item['ad_type'] . "_" . $item['unique_id'] . "'><div><form name='remove' action='saveable.php' method='get'><input type='submit' value='remove' /><input type='hidden' name='id' value='" . $item['unique_id'] . "'></form>" .$item['unique_id'] . "</div></li>";   

Added id to <li>.

Upvotes: 1

Related Questions