Results 1 to 4 of 4

Thread: pass javascript arrays in php POST method

  1. #1
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default pass javascript arrays in php POST method

    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!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Your best option is probably JSON. In Javascript, include the library http://www.json.org/json2.js, and in PHP call json_decode() on the passed string.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I'm sorry, I don't understand the question.

    JSON is a format, based on Javascript's object literal notation, for serialising structured data.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •