views:

87

answers:

2

My js code does POST order.php?order[]=1&order[]=2&order[]=3&order[]=4&order[]=5&&action=update How to reverse it to order.php?order[]=5&order[]=4&order[]=3&order[]=2&order[]=1&&action=update ?

JavaScript:
order=[];
//var reversed = $(this).sortable("serialize").split("&").reverse().join("&");
//var order = reversed + '&action=update'; //unfortunately it does not work so
$('#list ul').children('li').each(function(idx, elm) {
order.push(elm.id.split('-')[1])
});
$.post('order.php', {'order[]': order, action: 'update'});

HTML:
<ul>
<li id="oreder-5">5</li>
<li id="oreder-4">4</li>
<li id="oreder-3">3</li>
<li id="oreder-2">2</li>
<li id="oreder-1">1</li>
<ul>
A: 

Don't use order[] as parameter name. Use order[0], order[1], etc as parameter name if ordering is important for the server side.

BalusC
@BalusC. It is not important.
Binyamin
Then I don't see any need to reverse this.
BalusC
It is for to update data in MySql database ORDER BY position DESC
Binyamin
Then ordering *is* apparently important.
BalusC
A: 

Will

order.reverse();

do the trick?

Sean Kinsey
Thanks, Sean Kinsey! order.reverse(); before $.post(..); fixed it.
Binyamin