views:

42

answers:

2

I am using PHP as server side coding, and i want a set of values to be send to the server(in array format). how can i send that, and retrieve that array value at backend?

+1  A: 

Encode it as a JSON string and decode it using PHP json_decode

  • Use JSON.stringify (the source is available here) to convert your array to string at JavaScript end.
  • Send this string to your PHP page using an XMLHttpRequest.
  • In the PHP code, read the string from the $_POST variable and call json_encode on it.
Amarghosh
can you give me the code to send JSON data format using Javascript??
Harish Kurup
There is plenty of library to do that available on the Internet. Here are few example :http://devpro.it/JSON/files/JSON-js.htmlhttp://www.prototypejs.org/learn/json(etc.)
HoLyVieR
hey thank you! @Amarghosh and HoLyVieR.. i will try that :)
Harish Kurup
+1  A: 

Send the array as a json string, en then use json_decode

Redlab
how to send a JSON string using javascript or PHP??
Harish Kurup
indeed as above, plenty of javascript libraries that can do that for you, dojo, jquery, prototype etc.. or you create it your self see http://json.org/ for more info on json
Redlab