ScottW
2007-Apr-19 15:09 UTC
Looking for guidance re: updating several varying items at once
Hey gang - Yay, second day with Prototype. :D I finished up some other functions that I had initially built using mxAjax (ColdFusion-oriented bit) this morning, and started tackling the most involved mxAjax bit I''d done in this pile. I have a page that, upon load, lists out a row of info for each group of DB records it finds. One part of this info is a block of status info. I had coded up an mxAjax solution that would, on a set interval, pass in a list of IDs (one for each group of DB info) and the function would generate varying data and return it, and update the status info area for each item. The function would return new HTML for the status area (updating the wrapping div); a hex b/g color for that status info''s div (color indicating varying status types); and another status variable (just a simple 0 or 1). I''m trying to puzzle out how to deal with this with Prototype. With mxAjax, I was able to return a simple CF structure with all the data, and then pull the data out (using some built-in mxAjax JSON functionality) and toss it in the appropriate areas. I figure I can''t quite go the CF struct route, as Prototype is more generic (mxAjax actually uses Prototype for part of its functionality, heh). I''m guessing I''ll need to pass all this stuff in via XML. So - any pointers in the right direction on this would be excellent. Again, keep in mind this is day 2 of Prototype development for me. Still getting my feet wet. Thanks! --Scott --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Apr-19 15:47 UTC
Re: Looking for guidance re: updating several varying items at once
If you want to you can always prepare and return a json object as a part of the X-JSON header of your server-side script. Then, your onSuccess (or whatever) handler will get two parameters: the XHR object and a JSON object which is the one that''s created on the server. That way, on the client side, you''ll still just be working with a JSON object which you can use to fill the different portions of your page as necessary. I''m not sure how you can set a page header in ColdFusion, so if that isn''t something that you know how to do or if ColdFusion doesn''t really do it, you can always just return the JSON object as a string and then eval() it on the client-side taking appropriate precautions when using the eval() function. -- Dash -- ScottW wrote:> Hey gang - > > Yay, second day with Prototype. :D > > I finished up some other functions that I had initially built using > mxAjax (ColdFusion-oriented bit) this morning, and started tackling > the most involved mxAjax bit I''d done in this pile. > > I have a page that, upon load, lists out a row of info for each group > of DB records it finds. One part of this info is a block of status > info. I had coded up an mxAjax solution that would, on a set interval, > pass in a list of IDs (one for each group of DB info) and the function > would generate varying data and return it, and update the status info > area for each item. > > The function would return new HTML for the status area (updating the > wrapping div); a hex b/g color for that status info''s div (color > indicating varying status types); and another status variable (just a > simple 0 or 1). > > I''m trying to puzzle out how to deal with this with Prototype. With > mxAjax, I was able to return a simple CF structure with all the data, > and then pull the data out (using some built-in mxAjax JSON > functionality) and toss it in the appropriate areas. > > I figure I can''t quite go the CF struct route, as Prototype is more > generic (mxAjax actually uses Prototype for part of its functionality, > heh). I''m guessing I''ll need to pass all this stuff in via XML. > > So - any pointers in the right direction on this would be excellent. > Again, keep in mind this is day 2 of Prototype development for me. > Still getting my feet wet. > > Thanks! > --Scott > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ScottW
2007-Apr-19 19:33 UTC
Re: Looking for guidance re: updating several varying items at once
Ok, some progress here. First thing, I found that all the JSON stuff was in 1.5.1, and I had the 1.5.0 script. *bonk* Just doing some testing, I found I was able to parse out the example JSON structure data from the page: http://www.prototypejs.org/learn/json and see the values via alerts. Next, I created my own simple JSON structure, did the same thing, all''s fine. Now, when trying to pass that exact same JSON structure in from the page called via the ''url'' param, nada. I hit the page called via the ''url'' param, and the results are what I''m expecting - the JSON structure I''m creating - but it''s in plain text. Here''s the JSON structure my script is currently passing back (with test data); {"queueData": [ {"BLID": "3540", "BGColor": "fffff2"} ]}; My functions are currently as follows: ********************* function updateQueue() { var url = (valid url string); var ajax = new Ajax.Request( url, { method: ''get'', onComplete: updateQueueDivs, onFailure: reportError }); } updateQueueDivs = function(retValue) { alert(''start '' + retValue.responseText.length); var testdata = retValue.responseText.evalJSON(); alert(''hmm''); alert(testdata.queueData[0].BLID); } updateQueue(); ********************** This is all at the bottom of the script, so the last thing that gets hit is that ''updateQueue()'' call. It calls the first function, which then calls the ''updateQueueDivs'' function. I get a value in that first alert - but it''s 298, much larger than the length of the JSON structure string - and then, I don''t get the ''hmm'' alert - it''s choking on the evalJSON() bit. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ScottW
2007-Apr-19 19:35 UTC
Re: Looking for guidance re: updating several varying items at once
Something to add to the above post - I was able to successfully parse and spit out values from that JSON structure above, when just setting it in a local variable and going at it that way. The issue here is getting that same data out of the ajax function in a form I can parse. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ScottW
2007-Apr-19 20:55 UTC
Re: Looking for guidance re: updating several varying items at once
I found that it was my JSON structure that was slightly invalid. Stupid trailing semi-colon. Got rid of that and I''m able to parse my JSON structure fine now. *bonk!* --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---