php to javascript array

Discussion in 'Javascript' started by turnitup, Sep 13, 2006.

  1. turnitup

    turnitup Guest

    Dear all,

    I have a JavaScript function that talks to php using ajax. It can return
    values from php.

    Up until now, I have used it to return simple values such as integers or
    text strings.

    However, I wish now to return an array. Is it possible to create an
    array in php, format it in some way and pass it back to javascript for use?

    TIA

    Steve
    turnitup, Sep 13, 2006
    #1
    1. Advertising

  2. turnitup

    VK Guest

    turnitup wrote:
    > Is it possible to create an
    > array in php, format it in some way and pass it back to javascript for use?


    IMHO that would be much easier achieved by using JSON (see
    http://www.json.org, it also includes ready to use client-side script
    module and server-side bearers in PHP).
    VK, Sep 13, 2006
    #2
    1. Advertising

  3. turnitup

    Sawi Guest

    turnitup napisał(a):
    > using ajax.


    > to return simple values such as integers or
    > text strings.
    >
    > However, I wish now to return an array. Is it possible to create an
    > array in php, format it in some way and pass it back to javascript for use?


    First:
    If You say - AJAX - you mean Asynchronous JavaScript and *XML* - so You
    should use XML. You don't use AJAX :)
    Second:
    Find in google "JSON" - it help You in this problem.

    --
    Pozdrawiam,
    Sawi
    www.fruitysite.net
    Sawi, Sep 13, 2006
    #3
  4. turnitup wrote:


    > I have a JavaScript function that talks to php using ajax. It can return
    > values from php.


    > However, I wish now to return an array. Is it possible to create an
    > array in php, format it in some way and pass it back to javascript for use?


    There are various data interchange formats possible, one is JSON, which
    in terms of JavaScript is just a subset for what JavaScript allows
    syntactically for object and array literals, and which has lots of
    libraries for other languages, one being PHP, see the "JSON in PHP"
    entry on <http://www.json.org/>.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 13, 2006
    #4
  5. turnitup

    turnitup Guest

    turnitup wrote:
    > Dear all,
    >
    > I have a JavaScript function that talks to php using ajax. It can return
    > values from php.
    >
    > Up until now, I have used it to return simple values such as integers or
    > text strings.
    >
    > However, I wish now to return an array. Is it possible to create an
    > array in php, format it in some way and pass it back to javascript for use?
    >
    > TIA
    >
    > Steve


    Thank you everyone for your replies. Looks like JSON for now.
    turnitup, Sep 15, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted Zeng
    Replies:
    4
    Views:
    471
    Tim Arnold
    Oct 3, 2006
  2. Rajive Narain
    Replies:
    0
    Views:
    1,488
    Rajive Narain
    Sep 18, 2009
  3. eastcoastguyz
    Replies:
    1
    Views:
    92
    Flamer
    Jul 11, 2006
  4. Replies:
    3
    Views:
    186
    frothpoker
    Sep 4, 2006
  5. __
    Replies:
    1
    Views:
    107
    Gregor Kofler
    Oct 2, 2007
Loading...

Share This Page