PDA

View Full Version : pass javascript arrays in php POST method



Dennis_Gull
11-23-2008, 04:11 PM
Is there some smart way I can pass arrays in POST variables without exceeding some kind of POST limit? Let's say Im going to pass around 100 names from one page to another using javascript, I've heard that serialize works in php but im not sure why this would be better then just to use some kind of separator like this:

Dennis;Daniel;Johan;

and then use explode($_POST['name'],";").

also is there a way I can use associative array it would be even better.

any help will be appreciated!

Twey
11-24-2008, 02:42 AM
Your best option is probably JSON. In Javascript, include the library http://www.json.org/json2.js, and in PHP call json_decode (http://www.php.net/json-decode)() on the passed string.

Dennis_Gull
11-24-2008, 05:04 PM
Thanks I will take a look at it.

although from what I've seen it says:

An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

Will it just create a string with a separator or will it decode the array? :confused:

Twey
11-25-2008, 04:04 AM
I'm sorry, I don't understand the question.

JSON is a format, based on Javascript's object literal notation, for serialising structured data.