Search code examples
phpjsonprototypejsajax.request

Best way to pass JSON from Browser to PHP using Ajax.Request


Hi I have a JSON object that is a 2-dimentional array and I need to pass it to PHP using Ajax.Request (only way I know how). ...Right now I manually serialized my array using a js function...and get the data in this format: s[]=1&d[]=3&[]=4 etc. ....

my question is: Is there a way to pass the JSON object more directly/efficientely?..instead of serializing it myself?

Thanks for any suggestions, Andrew


Solution

  • You can also use Prototype's function toJSON() to convert an array into a JSON object. After passing it to server via Ajax call, simply use PHP's function json_decode() to decode the object.