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

Answers


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.


Pass the object as a JSON-string to PHP, and in PHP use the builtin json_decode to get a PHP-object from the string.

In Javascript, use a "stringify" function on your object to get it as a string, library available for example here: https://github.com/douglascrockford/JSON-js/blob/master/json2.js


Need Your Help

Laravel javascript location should be in view or public

php jquery laravel document-root

I have a javascript that requires a root directory path provided by PHP to call the JSON file.

Detect if image color space is CMYK or PMS

c# asp.net image colors

I'm creating a small image upload validator for this printing company, they need to make sure that an uploaded image has a color space of either CMYK or PMS.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.