问题
Im following a few tutorials to sort a list, but i can't get the DB to update. The drag drop side of things is working, also, i javascript alert() the serialize list onUpdate and the order is printed out as follows:
images_list[]=20&images_list[]=19
etc...
So the sorting and dragging is working fine, i just cant get the database to update, this is my code.
<script type="text/javascript">
Sortable.create("images_list", {
onUpdate: function() {
new Ajax.Request("processor.php", {
method: "post",
parameters: { data: Sortable.serialize("images_list") }
});
}
});
processor.php code:
//Connect to DB
require_once('connect.php');
parse_str($_POST['data']);
for ($i = 0; $i < count($images_list); $i++) {
$id = $images_list[$i];
mysql_query("UPDATE `images` SET `ranking` = '$i' WHERE `id` = '$id'");
}
Any ideas would be great, thankyou!
回答1:
Perhaps you have other tags in your elements for sorting. i would add tag: '':
<script type="text/javascript">
Sortable.create("images_list", {
onUpdate: function() {
new Ajax.Request("processor.php", {
method: "post",
parameters: { data: Sortable.serialize("images_list") }
});
},
tag: 'span'
});
</script>
Further i would check the path to your processor.php. I use:
new Ajax.Request("/youdir/processor.php", {
(Starting from DocumentRoot)
来源:https://stackoverflow.com/questions/3057830/sortable-with-scriptaculous-problems