Sortable with scriptaculous problems

强颜欢笑 提交于 2019-12-12 06:24:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!