Hello,

While AJAX is all about using Xml to transfer Asynchronously data to 
Javascript, in many cases it's more beneficial to use JSON (http://json.org) 
instead of XML, when transferring data from server to AJAX application. Many 
implementations of JSON are available for different languages. The easiest 
one is for JavaScript.

If you have to "parse" JSON-encoded data in JavaScript, the simplest way is 
to do it like this:

var myVeryCoolObject = eval("(" + aJSONtext + ")");

It means, you cannot use dojo.io.bind({ mimetype: "text/javascript" }), 
which does automatic evaluation of JavaScript  because it would fail for 
JSON.

It would be really handy to have a shortcut for automatic "parsing" of JSON 
and it is extremely easy to do so. Maybe some new MIME type should be 
introduced to specify JSON type. As far as I know there is no official JSON 
MIME type. So I propose to use "application/x-json" for now.

Thanks,

Eugene

PS: Some security minded people use simple JSON parser written in JavaScript 
to validate the input. I don't think it is a valid concern for Dojo. Not 
after totally insecure "text/javascript" evaluation. And I like it this 
way --- fast and simple.

PPS: Please note that "text/javascript" and "text/ecmascript" are to become 
officially obsolete. They are going to be replaced with 
"application/javascript" and "application/ecmascript" respectively. Should 
they be added as well? See details here: 
http://www.ietf.org/internet-drafts/draft-hoehrmann-script-types-03.txt 



Reply via email to