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 calljson_encode
on it.
Amarghosh
2010-06-22 12:25:34
can you give me the code to send JSON data format using Javascript??
Harish Kurup
2010-06-22 12:27:15
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
2010-06-22 12:32:43
hey thank you! @Amarghosh and HoLyVieR.. i will try that :)
Harish Kurup
2010-06-22 12:37:43
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
2010-06-22 12:49:55