S
S
semki0962016-05-15 15:49:18
PHP
semki096, 2016-05-15 15:49:18

How to process JSON generated by js-sortable?

Sorting blocks with the js-sortable plugin. After dragging, an array of the type is formed. Now, as I guess, it needs to be processed somehow, each ID needs to be assigned something like a weight. And pass to the handler somehow so probably["Степан", "Оля", "Владимир", "Алина"]

$.get('saveSortable.php', {тут наверно будет обработанный json - как написать не знаю} );
But how is this done correctly, how to process and transfer this array for writing to the weight base according to the ID of each block?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armozlo, 2016-05-16
@semki096

In saveSortable.php something like:

$i = 0;
foreach ($_GET['array'] as $name) {
      $db->query(" UPDATE `table` SET `sort` = ?i WHERE `name` = '?s' ", $i, $name);
      $i++;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question