Not too bad, FYI in NZ so its 9:45 here- premium coding time... if I could
just be bothered to start up my dev env...

Im pretty sure from my testing that the javascript execution just hung after
the evalJSON (at least in IE) when we were trying that- we had to manually
eval the responseText to get something we could iterate.
i suppose using data would work, I'm guessing this is because [ ... ] is not
valid json, yeah?
If there's no other way, i dont think the performance overhead is huge, more
of a readability issue and remembering I have to use .data

So to access this data, assuming it was returned in the body:

$A(xhr.responseText.evalJSON().data).each(function (hashObj) {
alert(hashObj); });

And via a header, which I think the key is x-json?
(in ASP.NET, response.addHeader("x-json:{data:[{hash1...},{hash2...}]}") I
think will put the data in an x-json header)
then $A(xhr.responseJSON).each(function (hashObj) { alert(hashObj); });

I've not done much json, but I like the ability to get objects back instead
of having to get text and parse it.

Gareth






On 6/9/07, Christophe Porteneuve <[EMAIL PROTECTED]> wrote:
>
>
> Hey Gareth, howzit? :-)
>
> Gareth Evans a écrit :
> > Could someone else identify the best way to get an array of hashes
> > (which is returned as a string from an ajax call) and then get something
> > you can iterate?
>
> So if I get you right, you're saying that the following responseText
> (just abbreviating with '...' in there):
>
> '[ { hash1... }, { hash2... } ...]'
>
> won't get eval'd properly when you do xhr.responseText.evalJSON
> ().  Correct?
>
> What if you tried to wrap it in an extra object with a single property,
> something like:
>
> '{ data: [ { hash1... }, { hash2... } ...] }'
>
> And then you'd access the data property of the eval'd object?  Would
> that work for you?  I'm sorry I don't have time to test this just now,
> but I thought I'd suggest a possible lead.
>
> 'HTH
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to