Hi Gang, prototype noob here. Im doing something stupid in my code and I need help solving problem. The problem occurs when I return some json from a page and try to evalJSON() it. string returned from the server looks like this: {"imageresults":[{"imageid":"0","image_title":"Elk in the yard","image_filename":"elk1.jpg","image_caption":""}, {"imageid":"1","image_title":"fasd;lfk","image_filename":"elk1.jpg","image_caption":""}, {"imageid":"2","image_title":"lkjhlkjh","image_filename":"elk1.jpg","image_caption":""}, {"imageid":"3","image_title":"kjhlkjh","image_filename":"elk1.jpg","image_caption":""}, {"imageid":"4","image_title":"kj;lkj","image_filename":"elk1.jpg","image_caption":""} ]} //without the line breaks Then, here is my ajax request: var request = new Ajax.Request(''getsomedata.php'', { method:''get'', onSuccess: function(transport){var myData transport.responseText.evalJSON();}, onFailure: errorOccured }); when I ''alert(responseText); without the ''evalJSON()'', I can see my json string, however when I use evalJSON() the output turns into [object][Object]. Any input to help solve this noob problem would be greatly appreciated. Mucho thanks, Deepsnow --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
hi, try: alert(responseText.imageresults[0].image_title); this should return> "Elk in the yard" hope that helps Bastian On 9/2/07, deepsnow <daneensign-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi Gang, > > prototype noob here. Im doing something stupid in my code and I need > help solving problem. > > The problem occurs when I return some json from a page and try to > evalJSON() it. > > string returned from the server looks like this: > > {"imageresults":[{"imageid":"0","image_title":"Elk in the > yard","image_filename":"elk1.jpg","image_caption":""}, > {"imageid":"1","image_title":"fasd;lfk","image_filename":"elk1.jpg > ","image_caption":""}, > {"imageid":"2","image_title":"lkjhlkjh","image_filename":"elk1.jpg > ","image_caption":""}, > {"imageid":"3","image_title":"kjhlkjh","image_filename":"elk1.jpg > ","image_caption":""}, > {"imageid":"4","image_title":"kj;lkj","image_filename":"elk1.jpg > ","image_caption":""} > ]} > > //without the line breaks > > > Then, here is my ajax request: > > var request = new Ajax.Request(''getsomedata.php'', > { > method:''get'', > onSuccess: function(transport){var myData > transport.responseText.evalJSON();}, > onFailure: errorOccured > }); > > when I ''alert(responseText); without the ''evalJSON()'', I can see my > json string, however when I use evalJSON() the output turns into > [object][Object]. > > Any input to help solve this noob problem would be greatly > appreciated. > > Mucho thanks, > > Deepsnow > > > > >-- -- spread the word ... see www.browsehappy.com ;o) Calvin: Weekends don''t count unless you spend them doing something completely pointless. Join the Greater IBM Connection ( http://www.xing.com/premiumgroup-6291.d26b7d) --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Bastian, It didnt do anything. I believe the problem lies somewhere in converting the string to a json object. My understanding is that unless I eval the string that is echo''d from my php it is still just a string. I can alert the string as it is, but when I try to run an evalJSON() on it, I get [object][Object] alerted and no json object to use. Dane On Sep 2, 12:00 pm, "Bastian Feder" <bastian.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, > > try: > alert(responseText.imageresults[0].image_title); > > this should return> "Elk in the yard" > > hope that helps > > Bastian > > On 9/2/07, deepsnow <daneens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hi Gang, > > > prototype noob here. Im doing something stupid in my code and I need > > help solving problem. > > > The problem occurs when I return some json from a page and try to > > evalJSON() it. > > > string returned from the server looks like this: > > > {"imageresults":[{"imageid":"0","image_title":"Elk in the > > yard","image_filename":"elk1.jpg","image_caption":""}, > > {"imageid":"1","image_title":"fasd;lfk","image_filename":"elk1.jpg > > ","image_caption":""}, > > {"imageid":"2","image_title":"lkjhlkjh","image_filename":"elk1.jpg > > ","image_caption":""}, > > {"imageid":"3","image_title":"kjhlkjh","image_filename":"elk1.jpg > > ","image_caption":""}, > > {"imageid":"4","image_title":"kj;lkj","image_filename":"elk1.jpg > > ","image_caption":""} > > ]} > > > //without the line breaks > > > Then, here is my ajax request: > > > var request = new Ajax.Request(''getsomedata.php'', > > { > > method:''get'', > > onSuccess: function(transport){var myData > > transport.responseText.evalJSON();}, > > onFailure: errorOccured > > }); > > > when I ''alert(responseText); without the ''evalJSON()'', I can see my > > json string, however when I use evalJSON() the output turns into > > [object][Object]. > > > Any input to help solve this noob problem would be greatly > > appreciated. > > > Mucho thanks, > > > Deepsnow > > -- > -- > spread the word ... seewww.browsehappy.com;o) > > Calvin: Weekends don''t count unless you spend them doing something > completely pointless. > > Join the Greater IBM Connection (http://www.xing.com/premiumgroup-6291.d26b7d)--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
hi, trying something other... If I return JSON from the php I set the HTTP header generated by the PHP- script to "text/javascript" This forces prototype to eval the responseText directly as JSON. So you can treat the response as JSON object ... so try: header(''Content-type: text/javascript''); or: add: header("X-JSON: $jsonData"); to your php script, but be aware doing so your data will be transported via the limited GET method. hope that helps Bastian On 9/2/07, deepsnow <daneensign-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi Bastian, > > It didnt do anything. I believe the problem lies somewhere in > converting the string to a json object. > My understanding is that unless I eval the string that is echo''d from > my php it is still just a string. > I can alert the string as it is, but when I try to run an evalJSON() > on it, I get [object][Object] alerted and no json object to use. > > Dane > > On Sep 2, 12:00 pm, "Bastian Feder" <bastian.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > hi, > > > > try: > > alert(responseText.imageresults[0].image_title); > > > > this should return> "Elk in the yard" > > > > hope that helps > > > > Bastian > > > > On 9/2/07, deepsnow <daneens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > Hi Gang, > > > > > prototype noob here. Im doing something stupid in my code and I need > > > help solving problem. > > > > > The problem occurs when I return some json from a page and try to > > > evalJSON() it. > > > > > string returned from the server looks like this: > > > > > {"imageresults":[{"imageid":"0","image_title":"Elk in the > > > yard","image_filename":"elk1.jpg","image_caption":""}, > > > {"imageid":"1","image_title":"fasd;lfk","image_filename":"elk1.jpg > > > ","image_caption":""}, > > > {"imageid":"2","image_title":"lkjhlkjh","image_filename":"elk1.jpg > > > ","image_caption":""}, > > > {"imageid":"3","image_title":"kjhlkjh","image_filename":"elk1.jpg > > > ","image_caption":""}, > > > {"imageid":"4","image_title":"kj;lkj","image_filename":"elk1.jpg > > > ","image_caption":""} > > > ]} > > > > > //without the line breaks > > > > > Then, here is my ajax request: > > > > > var request = new Ajax.Request(''getsomedata.php'', > > > { > > > method:''get'', > > > onSuccess: function(transport){var myData > > > transport.responseText.evalJSON();}, > > > onFailure: errorOccured > > > }); > > > > > when I ''alert(responseText); without the ''evalJSON()'', I can see my > > > json string, however when I use evalJSON() the output turns into > > > [object][Object]. > > > > > Any input to help solve this noob problem would be greatly > > > appreciated. > > > > > Mucho thanks, > > > > > Deepsnow > > > > -- > > -- > > spread the word ... seewww.browsehappy.com;o) > > > > Calvin: Weekends don''t count unless you spend them doing something > > completely pointless. > > > > Join the Greater IBM Connection (http://www.xing.com/premiumgroup-6291.d26b7d) > > > > >-- -- spread the word ... see www.browsehappy.com ;o) Calvin: Weekends don''t count unless you spend them doing something completely pointless. Join the Greater IBM Connection (http://www.xing.com/premiumgroup-6291.d26b7d) --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Bastian, I just got it to work. I removed ''json'' as an argument to the onSuccess function and I used ''.evalJSON();'' on my responseText. Before: onSuccess: function(transport, json){ var mydata = transport.responseText; alert(mydata.imageresults[1].imageid); } After: onSuccess: function(transport){ var mydata = transport.responseText.evalJSON(); alert(mydata.imageresults[1].imageid); } I understood that using the json arg in the anonymous function would take care of things, but I clearly I misunderstood. I guess the json arg in the function is meant to signal that the information coming in has been Header''ed '' as javascript or JSON, depending on which of your suggestions I take. I better go study prototype more. Thanks for your help! Dane On Sep 2, 12:37 pm, "Bastian Feder" <bastian.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, > > trying something other... > > If I return JSON from the php I set the HTTP header generated by the > PHP- script to "text/javascript" > This forces prototype to eval the responseText directly as JSON. So > you can treat the response as JSON object ... > > so try: > > header(''Content-type: text/javascript''); > > or: > > add: > > header("X-JSON: $jsonData"); > > to your php script, but be aware doing so your data will be > transported via the limited GET method. > > hope that helps > > Bastian > > On 9/2/07, deepsnow <daneens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hi Bastian, > > > It didnt do anything. I believe the problem lies somewhere in > > converting the string to a json object. > > My understanding is that unless I eval the string that is echo''d from > > my php it is still just a string. > > I can alert the string as it is, but when I try to run an evalJSON() > > on it, I get [object][Object] alerted and no json object to use. > > > Dane > > > On Sep 2, 12:00 pm, "Bastian Feder" <bastian.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > hi, > > > > try: > > > alert(responseText.imageresults[0].image_title); > > > > this should return> "Elk in the yard" > > > > hope that helps > > > > Bastian > > > > On 9/2/07, deepsnow <daneens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi Gang, > > > > > prototype noob here. Im doing something stupid in my code and I need > > > > help solving problem. > > > > > The problem occurs when I return some json from a page and try to > > > > evalJSON() it. > > > > > string returned from the server looks like this: > > > > > {"imageresults":[{"imageid":"0","image_title":"Elk in the > > > > yard","image_filename":"elk1.jpg","image_caption":""}, > > > > {"imageid":"1","image_title":"fasd;lfk","image_filename":"elk1.jpg > > > > ","image_caption":""}, > > > > {"imageid":"2","image_title":"lkjhlkjh","image_filename":"elk1.jpg > > > > ","image_caption":""}, > > > > {"imageid":"3","image_title":"kjhlkjh","image_filename":"elk1.jpg > > > > ","image_caption":""}, > > > > {"imageid":"4","image_title":"kj;lkj","image_filename":"elk1.jpg > > > > ","image_caption":""} > > > > ]} > > > > > //without the line breaks > > > > > Then, here is my ajax request: > > > > > var request = new Ajax.Request(''getsomedata.php'', > > > > { > > > > method:''get'', > > > > onSuccess: function(transport){var myData > > > > transport.responseText.evalJSON();}, > > > > onFailure: errorOccured > > > > }); > > > > > when I ''alert(responseText); without the ''evalJSON()'', I can see my > > > > json string, however when I use evalJSON() the output turns into > > > > [object][Object]. > > > > > Any input to help solve this noob problem would be greatly > > > > appreciated. > > > > > Mucho thanks, > > > > > Deepsnow > > > > -- > > > -- > > > spread the word ... seewww.browsehappy.com;o) > > > > Calvin: Weekends don''t count unless you spend them doing something > > > completely pointless. > > > > Join the Greater IBM Connection (http://www.xing.com/premiumgroup-6291.d26b7d) > > -- > -- > spread the word ... see www.browsehappy.com;o) > > Calvin: Weekends don''t count unless you spend them doing something > completely pointless. > > Join the Greater IBM Connection (http://www.xing.com/premiumgroup-6291.d26b7d)--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
i think you misunderstood what json actually is. if you alert an json evaluated string you''ll get the same as if you''d alert javascript objects or functions. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Markus, I understand json =), its the prototype function that was giving me grief. Specifically the json arg in ''function'', and its purpose and requirement to set headers in my php. After removing that arg and using the evalJSON() method. My data was then correctly being processed into a js object. Dane On Sep 3, 2:31 am, Markus Hammer <yaya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i think you misunderstood what json actually is. > if you alert an json evaluated string you''ll get the same as if you''d > alert javascript objects or functions.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---