Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKnowledgeWoods Consulting
5,607 PointsHow to post li values through serialize using ajax.
Hi, Thanks in advance. I want to post li values through serialize using ajax.
My code is: <script> $(document).ready( function() { $("#sortme").sortable({ update : function () { serial = $('#sortme').sortable('serialize'); $.ajax({ url: "sort.php", type: "post", data: serial, success: function(data){ $('#result').html(data); }, error: function(){ alert("theres an error with AJAX"); } }); } }); } ); </script>
<ul id="sortme">
<?php include_once("db.php"); // Getting menu items from DB $select = $conn->query("SELECT * FROM drag ORDER BY position ASC"); foreach($select as $row){
echo '<li id="menu_' . $row['id'] . '">' . $row['title'] . "</li>\n"; } ?>
</ul>
<!-- sort.php -->
<?php include_once("db.php"); $menu = $_POST['menu'];
for ($i = 0; $i < count($menu); $i++) {
$conn->query("UPDATE drag SET position
=" . $i . " WHERE id
='" . $menu[$i] . "'");
}
?>
How the term "menu" is coming to sort.php page ???