0

I have a form that includes several input text fields and a list that's sortable (se code below). The function below retrieves the new positions that's saved to an array (order). However, what I want is to include the array in the form so that when the user is finished with the sorting, has filled in the text fields and submits the form this array will be apart of the form.

So, how could I get this array into the form with AJAX?

$('#listElements').sortable({
            //revert: true,
            update: function(event, ui) {

                var order = [];
                $('.listObject li').each(function (e) {
                    order.push($(this).attr('id'));
                });
                $.ajax({
                    url: "/index.php?type=list&action=showList&listId=1",
                    type: "post",
                    data: {
                        order_data: order
                    }
                }).success(function (data) {
                    console.log(data);
                });
            }
        });

NOTE: To make it clear, I want to get the array into the form.

holyredbeard
  • 19,619
  • 32
  • 105
  • 171
  • possible duplication of `http://stackoverflow.com/questions/4239460/serializing-an-array-in-jquery` – flec Oct 23 '12 at 13:41
  • You want to get array (from order) into form, or You want to get it into index.php ? – koshin Oct 23 '12 at 13:40

1 Answers1

1

send it as a JSON encoded string and decode it serverside. As far as I know jquery has a array to JSON function and php got json_decode()

Soundz
  • 1,308
  • 10
  • 17