[Gllug] OT: Anyone know Jquery & JSON ?

Walter Stanish walter.stanish at saffrondigital.com
Tue Nov 9 14:16:13 UTC 2010


>> Now I didn't really expect jQuery to just use raw JSON, but I did assume
>> it would use something simple and fairly universal like standard HTTP
>> URL encoding or base64 encoding to serialize the JSON so it would sit
>> nicely within HTTPs URL format.
>
> Here is what the jQuery manual [0] says:
>  "Data that is sent to the server is appended to the URL as a query
> string. If the value of the data parameter is an object (map), it is
> converted to a string and url-encoded before it is appended to the
> URL."
>
> So it is indeed URL encoded.  I have never tried it, but my guess is
> in your Python code you need to first decode the json qeury parameter
> and then pass it through json.loads()

For nontrivial / complex data structures (without the need for
?key=val format conversion, or extra-long URLs) I would suggest making
jQuery  HTTP POST a JSON string vs. transforming in to GET arguments.

Side effects:
 - Shorter URL
 - Less junk in log files
 - Possibly neater/faster server-side code, in particular if you have
structures of some depth to pass
 - Because deep structures are supported, your call is more
flexible/future-proofed

Just my 2c. (Done WAY too much of this stuff in my time)

- Walter
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list