Hey,
Gareth Evans a écrit :
> $A(xhr.responseText.evalJSON().data).each(function (hashObj) {
> alert(hashObj); });
Just pass alert to each, it'll be easier. But on arrays you'll get
sucky toString's, so use inspect, which then warrants the use of an
anonymous function. For instance:
xhr.responseText.evalJSON().each(alert) // Sucky toString's...
xhr.responseText.evalJSON().each(function(o) {
console.log($H(o).inspect()); // Better representations
});
There's no need for $A: what you get is already an Array, which is
guaranteed extended no matter what browser you're on. And the anonymous
function here does not do anything extra to alert/console.log, so why
bother wrapping the original call?
> And via a header, which I think the key is x-json?
Forget X-JSON :-) It's only intended for on-the-side, small JSON data
accompanying non-JSON results, such as XHTML fragments. If you're
looking for JSON as a main data format for your response, put it in the
response's body and set the Content-Type accordingly (application/json,
IIRC), so you'll be better off when 1.5.2 comes out :-)
> response.addHeader("x-json:{data:[{hash1...},{hash2...}]}") I think will
Also, X-JSON is all uppercase.
> I've not done much json, but I like the ability to get objects back
> instead of having to get text and parse it.
Totally. Screw XML and its daunting requirements for DOM traversal!
--
Christophe Porteneuve aka TDD
[EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---