Monday 12 March 2007

New Prototype version 1.5.1 announced

The new Prototype 1.5.1 release candidate was announced last friday March 9th, 2007 and there is now direct support for encoding and decoding the lightweight data-interchange format JSON. This makes it possible to parse the JSON response from the server straight with Prototype and eliminates the use of the default 'evil' javascript built-in eval or the need for the use of the official json.js library.

Here is the new way to handle JSON encoded server responses.

new Ajax.Request('/recordshelf/foo' + id, {

method:'post',

requestHeaders: {Accept: 'text/x-json'},

onSuccess: function(transport){

var json = transport.responseText.evalJSON(true);
// use the Json String for convenience to add data to the DOM

}

});
For an overview of what has been changed and added have a look at the announcement on the Prototype blog.

1 comment:

Unknown said...

Wouldn't want to disappoint you... but String#evalJSON uses the "evil" eval internally. That's the whole point of JSON...!