Marty Haught
2005-Sep-30 14:08 UTC
[Rails-spinoffs] Converting text into a javascript array
Hey Guys, I know this isn''t specific to scriptaculous libraries but it''s something that I''m exploring as I use the ajax functions in prototype. My application server is not rails but java and I was thinking of returning a javascript array in the ajax response. When I get back my response is it, of course, text and I''m not sure how best to convert it into a javascript object. Is there some neat trick to this or do I need to parse the string and create the array manually? I appreciate any feedback or links to possible answers you might have. Cheers, Marty
Have you looked into JSON? Basically, your server sends a string like "[''a'', ''b'', ''c'']" and you do: var letters = eval(response_from_server); http://www.crockford.com/JSON/index.html On 9/30/05, Marty Haught <marty@razorstream.com> wrote:> Hey Guys, > > I know this isn''t specific to scriptaculous libraries but it''s something > that I''m exploring as I use the ajax functions in prototype. My > application server is not rails but java and I was thinking of returning > a javascript array in the ajax response. When I get back my response is > it, of course, text and I''m not sure how best to convert it into a > javascript object. Is there some neat trick to this or do I need to > parse the string and create the array manually? > > I appreciate any feedback or links to possible answers you might have. > > Cheers, > Marty > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- rick http://techno-weenie.net
Andrew Kaspick
2005-Sep-30 14:19 UTC
[Rails-spinoffs] Converting text into a javascript array
Is JSON what you want? http://www.crockford.com/JSON/index.html On 9/30/05, Marty Haught <marty@razorstream.com> wrote:> Hey Guys, > > I know this isn''t specific to scriptaculous libraries but it''s something > that I''m exploring as I use the ajax functions in prototype. My > application server is not rails but java and I was thinking of returning > a javascript array in the ajax response. When I get back my response is > it, of course, text and I''m not sure how best to convert it into a > javascript object. Is there some neat trick to this or do I need to > parse the string and create the array manually? > > I appreciate any feedback or links to possible answers you might have. > > Cheers, > Marty > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Marty Haught
2005-Sep-30 14:26 UTC
[Rails-spinoffs] Converting text into a javascript array
Andrew Kaspick wrote:>Is JSON what you want? > >http://www.crockford.com/JSON/index.html >You know what''s funny? After I sent the email I started looking at json. It most likely is since it appears that javascript doesn''t have a way to cast a string into another object (that I can tell). But it seems json is my answer as it should also make the java conversion into the array easier. Thanks for the quick responses. Cheers, Marty
SPENDLOVE, Matt, FM
2005-Oct-03 03:21 UTC
[Rails-spinoffs] Converting text into a javascript array
Or you could just use the native String.split ? <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_O bjects:String:split> <http://bclary.com/2004/09/26/boot-camp-javascript> Matt> -----Original Message----- > From: rails-spinoffs-bounces@lists.rubyonrails.org > [mailto:rails-spinoffs-bounces@lists.rubyonrails.org] On > Behalf Of Marty Haught > Sent: 30 September 2005 18:32 > To: rails-spinoffs@lists.rubyonrails.org > Subject: [Rails-spinoffs] Converting text into a javascript array > > > Hey Guys, > > I know this isn''t specific to scriptaculous libraries but > it''s something > that I''m exploring as I use the ajax functions in prototype. My > application server is not rails but java and I was thinking > of returning > a javascript array in the ajax response. When I get back my > response is > it, of course, text and I''m not sure how best to convert it into a > javascript object. Is there some neat trick to this or do I need to > parse the string and create the array manually? > > I appreciate any feedback or links to possible answers you might have. > > Cheers, > Marty > _______________________________________________ > Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >*********************************************************************************** The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. Authorised and regulated by the Financial Services Authority This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate. Visit our websites at: http://www.rbs.co.uk/CBFM http://www.rbsmarkets.com ********************************************************************************