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.

2
  • You want to get array (from order) into form, or You want to get it into index.php ? Commented Oct 23, 2012 at 13:40
  • possible duplication of http://stackoverflow.com/questions/4239460/serializing-an-array-in-jquery Commented Oct 23, 2012 at 13:41

1 Answer 1

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()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.