php to javascript array

T

turnitup

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
 
V

VK

turnitup said:
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).
 
S

Sawi

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.
 
M

Martin Honnen

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/>.
 
T

turnitup

turnitup said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top