This document
http://www.w3schools.com/jsref/jsref_toSource_math.asp
suggests that toSource is not available on IE either.

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?
Take for example, returning a hash of 'rows' to display, or maybe a dynamic
update of a form metadata (what fields are visible/required), often you need
to return a list/array of objects.

I've also used the manual eval code before as I wasn't returning it in a
json header (just in the body) but it seems rather.. messy.

So basically, i'm asking what Mark is asking-

Mark; how did toSource help? according to the documentation url above, that
returns the source, so it would be alerting a string representation of your
var test- not an array.

Gareth


On 6/8/07, Mark Holton <[EMAIL PROTECTED]> wrote:
>
> aha, found it.  the toSource() method of object does the trick.  (is there
> a way in Proto that's better?)
>
> ...
>
> > var jsonarray = transport.responseText.evalJSON(true);
> > var test = jsonarray.toSource(); //returns my array of hashes
> > alert(test);
> >
> ...
>
> Thanks once again for the sounding board ...(seems to usually work when
> debugging)
>
> cheers, all-
>
>
> On 6/7/07, Mark Holton <[EMAIL PROTECTED]> wrote:
> >
> > Thanks.  Unfortunately, that works the same as what I was trying with
> > "var jsonarray = transport.responseText.evalJSON(true);".
> >
> > ...I know the string passed back is:
> >
> > > [{"VIDID":3359,"VIDPATHSTR":"/SS/vids/123","VIDDESCRIP":"test22"},{"VIDID":3358,"VIDPATHSTR":"/SS/vids/123","VIDDESCRIP":"some
> > > other descrip"}]
> > >
> >
> > When I display the alert below, I receive the message:
> >
> > [object Object]
> > >
> >
> > When I try to access an element of that array, via
> > alert(jsonarray[1])... I return:
> >
> > > undefined
> > >
> >
> > new Ajax.Request(url,
> >             {
> >                 method: 'post',
> >                 parameters: pars,
> >                 onComplete: function(transport)  //get from JSON string
> >                   {
> >                     var jsonarray = transport.responseText.evalJSON
> > (true);
> >                     alert(jsonarray);
> >                     var item = jsonarray[1];
> >                     alert(item);
> >                   }
> >             }
> >         );
> >
> > On 6/7/07, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote:
> > >
> > >
> > > I use this
> > >
> > > var obj = eval( "(" + t.responseText + ")" );
> > >
> > > Hope that helps;
> > >
> > > On Jun 8, 12:18 am, "Mark Holton" < [EMAIL PROTECTED]> wrote:
> > > > Using Proto 1.5.1:
> > > >
> > > > Let's say my server side code returns a JSON string with is an Array
> > > of
> > > > hashes (with name-value pairs), such as in this case, where I return
> > > an
> > > > array of 3 hashes via an Ajax.Request invocation:
> > > >
> > > [{"VIDID":3359,"VIDPATHSTR":"/SS/vids/123","VIDDESCRIP":"test22"},{"VIDID":3358,"VIDPATHSTR":"
> > > > /SS/vids/123","VIDDESCRIP":"some other descrip"}]
> > > >
> > > > While the following works very nicely for a single JSON object
> > > returned...
> > > > doesn't work directly on an array...
> > > > var json = transport.responseText.evalJSON(true);
> > > >
> > > > In Prototype, what's the easiest way to turn that returned JSON
> > > string of an
> > > > array of hashes into an object that's accessible via name/value
> > > pairs in my
> > > > function?
> > > >
> > > > Many thanks for any words of wisdom!
> > > > cheers,
> > > > Mark
> > >
> > >
> > >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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