Hi,

I've committed my work on JSON to the new ajax branch Mislav just set
up (thanks!).

http://dev.rubyonrails.org/browser/spinoffs/prototype/branches/ajax

What's new:

1. a JSON encoder based on the work of Douglas Crockford (http://
www.json.org) which adds the following:
    a) toJSON method to String.prototype, Array.prototype,
Hash.prototype, Number.prototype, Date.prototype and Object.
        ['a', {'b': null}].toJSON();
        // equivalent to:
        Object.toJSON(['a', {'b': null}];
        // -> '[\"a\",{\"b\":null}]'
    b) a times method to String.prototype.
        'test'.times(3);
        // -> 'testtesttest'
    c) a toPaddedString method to Number.prototype.
        (4).toPaddedString(2);
        // -> '04'
        (255).toPaddedString(2, 16);
        // -> 'ff'

2. A JSON parser:
    a) adds an evalJSON method to String.prototype which can take an
optional sanitize parameter

3. a new Ajax.Response object:
     a) acts as a simple wrapper around the transport object
     b) adds getHeader() and getAllHeaders() wrapped in a try...catch
block
     c) adds a transport property which is just a simple pointer to
this.transport
     d) adds a request property which is also a simple pointer to the
current Ajax.Request instance
     c) the parsed JSON object is available as the responseJSON
property of the response:
         onComplete: function(response) { response.responseJSON }
     e) adds a headerJSON property which contains the evaluated JSON
of the x-json header (this is still passed as a second argument of the
callbacks for backwards compatibility, but the idea is to deprecate
this behavior in future versions).

4. automatic evaluation of responseText if the Content-Type is set to
application/json OR if the evalJSON option of Ajax.Request is set to
true. The evaluated JSON is available as the responseJSON property of
the response object.

5. Automatic sanitizing before evaluation of the returned JSON if  the
sanitizeJSON option of Ajax.Request is set to true.

Currently, not all tests pass for Ajax.Response, as the support for
varies a lot depending on the browser and I don't know how much of
these discrepancies we really feel like smoothing out. This is
something we really need to discuss.

For reference: http://www.w3.org/TR/XMLHttpRequest/

I've also modified the rake testing, adding a isRunningFromRake param
to the query string and support for WebKit and Opera testing (these
shouldn't necessarily be merged to trunk IMO).

any comments welcomed.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to