2

I have a jQuery array and I want to use it in an AJAX call with my PHP script, can anyone help me do this?

var things = {
  "foo": ["bar", "baz"],
  "bar": 1234
};

var output = "?foo[]=bar&foo[]=baz&bar=1234";

Thanks!!

1

2 Answers 2

5

$.param(myobj, true)

From the manual:

As of jQuery 1.4, the $.param() method serializes deep objects recursively to accommodate modern scripting languages and frameworks such as PHP and Ruby on Rails. You can disable this functionality globally by setting jQuery.ajaxSettings.traditional = true;.

As of jQuery 1.8, the $.param() method no longer uses jQuery.ajaxSettings.traditional as its default setting and will default to false. For best compatibility across versions, call $.param() with an explicit value for the second argument and do not use defaults.

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

Comments

2

$.param(things, true)

The above will help you here. The second parameter allows for arrays. Make sure you have jQuery installed

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.