1

I have a jQuery sortable with 3 list items with the following ID's

id_1
id_2
id_3

This gets sorted by the user and serialized using the following code

var order = $("#rank").sortable('serialize');
saveResponses(order);

and printed. Which looks like this...

id[]=1&id[]=3&id[]=2

So I've got a couple of questions...

  1. Why does the underscore get converted to "[]="

  2. Is there a strait forward way to get an array of the original ID's? I mean without just doing a string split, and replacing the characters?

2
  • 1
    Please have a look at the official Docu: It works by default by looking at the id of each item in the format "setname_number", and it spits out a hash like "setname[]=number&setname[]=number". so far for your serialize problem Commented Jul 7, 2016 at 16:59
  • 1
    To get an array of the ids simply use the build-in function toArray Commented Jul 7, 2016 at 17:01

1 Answer 1

3

serialize converts the data into a query string. The data is formatted (converted to an array) so you can use it in a URL as a query string (GET data).

You probably want toArray:

var order = $("#rank").sortable('toArray');
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.