Welcome Guest, Not a member yet? Register   Sign In
jquery post & serialize
#4

[eluser]boldyellow[/eluser]
I'm also wrestling with sortable list items (big surprise, I'm a designer who's not JS saavy and still learning CI).

And yet... it kinda works: list items drag and the array is echoed in the #info box.

But the row order does not update in the database. And it doesn't seem very MVC (it calls on a separate PHP file).

It's not gonna be a long list, so performance is not huge concern.


Database: gallery_names
Code:
| id  |  name  |  order |


View
In the view header:
Code:
$(document).ready(function() {
    $("#sortable-list").sortable({
      update : function () {
          var order = $('#sortable-list').sortable('serialize');
          $("#info").load("http://localhost/ci/process-sortable.php?"+order);
      }
    });
});

And in the view body:

Code:
<div id="info">Waiting...</div>

<ul id="sortable-list">
    <li id="listfield_01">Gallery 1</li>
    <li id="listfield_02">Gallery 2</li>
    <li id="listfield_03">Gallery 3</li>
</ul>


Separate PHP File: process-sortable.php

Code:
foreach ($_GET['listfield'] as $order => $item) :
    $sql[] = "UPDATE `gallery_names` SET `order` = $order WHERE `id` = $item";
endforeach;

echo '<pre>';
print_r ($sql);
echo '</pre>';


Taking a stab here...

When the header script posts, it should go to the controller which gets the $_POST.

The controller loads a model with a variation of the process-sortable code and updates the db(?)

Thanks for any guidance!


Messages In This Thread
jquery post & serialize - by El Forum - 09-19-2010, 10:15 AM
jquery post & serialize - by El Forum - 09-19-2010, 07:19 PM
jquery post & serialize - by El Forum - 09-19-2010, 07:27 PM
jquery post & serialize - by El Forum - 10-02-2010, 10:59 AM
jquery post & serialize - by El Forum - 10-03-2010, 04:05 PM
jquery post & serialize - by El Forum - 10-03-2010, 05:10 PM
jquery post & serialize - by El Forum - 10-04-2010, 04:38 PM
jquery post & serialize - by El Forum - 10-04-2010, 06:13 PM
jquery post & serialize - by El Forum - 10-05-2010, 04:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB