I am trying to make a gallery of photos poll the server and see if there''s anything more recent. I am having trouble figuring out how to get Ajax.PeriodicalUpdater to send a dynamic value to the server. Is this something I can set up in onCreate? If so, how do I then add it to the parameters before the post is sent? This, very obviously, doesn''t work -- it keeps sending the same value for "last", even though my updater script destroys and replaces the span $(''latest'') if it notices a change: Event.observe(window,''load'',function(){ new Ajax.PeriodicalUpdater(''gallery'',''update.php'',{ parameters: {last:$(''latest'').innerHTML}, insertion: Insertion.Top, frequency:30, decay:2 } ); }); Thanks in advance, Walter --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Justin Perkins
2008-Jan-18 15:43 UTC
Re: design pattern help needed for periodical updater
On Jan 18, 2008 9:33 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> > I am trying to make a gallery of photos poll the server and see if > there''s anything more recent. I am having trouble figuring out how to > get Ajax.PeriodicalUpdater to send a dynamic value to the server.Parameters are just normal key/value pairs, same as form POSTs and querystrings. You can build up the parameters separately pass them to the parameters option as either an ampersand (&) separated list of key/values, or you can pass in a Hash object. Note the lack of curly brackets (hash object) if using the string method vs. the second style which uses a hash. new Ajax.PeriodicalUpdater(''gallery'',''update.php'',{ parameters: ''latest='' + escape($(''latest'').innerHTML), insertion: Insertion.Top, frequency:30, decay:2 } ); // or... new Ajax.PeriodicalUpdater(''gallery'',''update.php'',{ parameters: { latest: $(''latest'').innerHTML }, insertion: Insertion.Top, frequency:30, decay:2 } ); -justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2008-Jan-18 15:56 UTC
Re: design pattern help needed for periodical updater
On 18/01/2008, Justin Perkins <justinperkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Jan 18, 2008 9:33 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > > > I am trying to make a gallery of photos poll the server and see if > > there''s anything more recent. I am having trouble figuring out how to > > get Ajax.PeriodicalUpdater to send a dynamic value to the server. > > Parameters are just normal key/value pairs, same as form POSTs and > querystrings. You can build up the parameters separately pass them to > the parameters option as either an ampersand (&) separated list of > key/values, or you can pass in a Hash object. Note the lack of curly > brackets (hash object) if using the string method vs. the second style > which uses a hash. > > new Ajax.PeriodicalUpdater(''gallery'',''update.php'',{ > parameters: ''latest='' + escape($(''latest'').innerHTML), > insertion: Insertion.Top, > frequency:30, > decay:2 > } > ); > > // or... > new Ajax.PeriodicalUpdater(''gallery'',''update.php'',{ > parameters: { latest: $(''latest'').innerHTML }, > insertion: Insertion.Top, > frequency:30, > decay:2 > } > ); > > > > > -justin >Justin, I think you missed the bit about this being a periodical updater. The same data is sent each time. Walter, I use the following code to timestamp all my AJAX calls. Makes sure each one is a unique request. Maybe you can adapt it. Ajax.Responders.register ({ onCreate: function(o_Requester) { // Timestamp each AJAX action. var o_Date = new Date(); o_Requester.url o_Requester.url + (o_Requester.url.indexOf(''?'') == -1 ? ''?'' : ''&'') + ''Stamp='' + o_Date.getTime(); if (b_Debug) { console.groupEnd(); } }, }); -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2008-Jan-18 15:59 UTC
Re: design pattern help needed for periodical updater
On Jan 18, 2008, at 10:43 AM, Justin Perkins wrote:> parameters: { latest: $(''latest'').innerHTML },Thanks, but this is precisely what I am doing in my example, and it isn''t working -- each time the PeriodicalUpdater fires, it sends the same value, even though it does update the page with newer photos. Trouble is, it keeps sending the same updated photos over and over, never getting the message that "latest" is different. Is there a scope issue here? Is the fact that the updater is wrapped inside a page listener the reason why the variable value never changes? Thanks again, Walter --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Justin Perkins
2008-Jan-18 16:06 UTC
Re: design pattern help needed for periodical updater
On Jan 18, 2008 9:59 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Thanks, but this is precisely what I am doing in my example, and it > isn''t working -- each time the PeriodicalUpdater fires,Sorry Walter, misread your code as just sending the raw data, not as a key/value pair. Have you considered keeping track of the latest photo ID with a javascript variable, which would be updated with every Ajax request? What does your HTML look like and what is a typical response from the server? Personally, I would turn evalScripts on, leave the first parameter of the Ajax.PeriodicalUpdater as an empty string (so nothing on the page is updated), then return plain JavaScript from the server (to insert new photos and update a variable used to keep track of the latest photo ID). -justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis wrote:> I am trying to make a gallery of photos poll the server and see if > there''s anything more recent. I am having trouble figuring out how to > get Ajax.PeriodicalUpdater to send a dynamic value to the server. Is > this something I can set up in onCreate? If so, how do I then add it > to the parameters before the post is sent? > > This, very obviously, doesn''t work -- it keeps sending the same value > for "last", even though my updater script destroys and replaces the > span $(''latest'') if it notices a change: > > Event.observe(window,''load'',function(){ > new Ajax.PeriodicalUpdater(''gallery'',''update.php'',{ > parameters: {last:$(''latest'').innerHTML}, > insertion: Insertion.Top, > frequency:30, > decay:2 > } > ); > }); >Try PeriodicalExecuter and Ajax.Updater: var updateGalery = function() { new Ajax.Updater(''gallery'', ''update.php'', { parameters: {last: $(''latest'').innerHTML}, insertion: Insertion.Top }); }; document.observe(''dom:loaded'', function() { new PeriodicalExecuter(updateGalery, 30); }); - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That would make sense that the value is constant. You''re sending a string value, not an object reference. I understand what you''re trying to do but it is simply not going to work, the string value is "copied by value" and whether or not the property changes it isn''t going to affect the value sent to the constructor. You need some way to have the PE retrieve fresh parameters and that may not be possible in this implementation. On the other end of things, you could potentially use session data to maneuver it so the back end knows what is the latest image and send it that way. Alternatively it isn''t hard to roll your own PE with a Ajax.Request and setInterval. Good Luck, Matt On Jan 18, 10:59 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On Jan 18, 2008, at 10:43 AM, Justin Perkins wrote: > > > parameters: { latest: $(''latest'').innerHTML }, > > Thanks, but this is precisely what I am doing in my example, and it > isn''t working -- each time the PeriodicalUpdater fires, it sends the > same value, even though it does update the page with newer photos. > Trouble is, it keeps sending the same updated photos over and over, > never getting the message that "latest" is different. > > Is there a scope issue here? Is the fact that the updater is wrapped > inside a page listener the reason why the variable value never changes? > > Thanks again, > > Walter--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2008-Jan-18 16:53 UTC
Re: design pattern help needed for periodical updater
On Jan 18, 2008, at 10:56 AM, Richard Quadling wrote:> Justin, I think you missed the bit about this being a periodical > updater. The same data is sent each time. > > Walter, I use the following code to timestamp all my AJAX calls. Makes > sure each one is a unique request. Maybe you can adapt it. > > Ajax.Responders.register > ({ > onCreate: function(o_Requester) > { > // Timestamp each AJAX action. > var o_Date = new Date(); > o_Requester.url > o_Requester.url + > (o_Requester.url.indexOf(''?'') == -1 ? ''?'' : ''&'') + > ''Stamp='' + o_Date.getTime(); > if (b_Debug) { console.groupEnd(); } > }, > }); > > > -- > ----- > Richard Quadling > Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!"Thanks very much to you and the clever giants! The following worked perfectly: Ajax.Responders.register({ onCreate: function(o_Requester){ // Get fresh variables var latest = $(''latest'').innerHTML; o_Requester.url o_Requester.url + (o_Requester.url.indexOf(''?'') == -1 ? ''?'' : ''&'') + ''last='' + latest; if (b_Debug) { console.groupEnd(); } } }); This keeps the value of ''latest'' in line with reality over the lifetime of the updater. Thanks again! Walter --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2008-Jan-19 11:01 UTC
Re: design pattern help needed for periodical updater
If you have multiple AJAX requests (not repeated ones, but different ones), then they will ALL get the latest value, so watch out for that. On 18/01/2008, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> > > On Jan 18, 2008, at 10:56 AM, Richard Quadling wrote: > > > Justin, I think you missed the bit about this being a periodical > > updater. The same data is sent each time. > > > > Walter, I use the following code to timestamp all my AJAX calls. Makes > > sure each one is a unique request. Maybe you can adapt it. > > > > Ajax.Responders.register > > ({ > > onCreate: function(o_Requester) > > { > > // Timestamp each AJAX action. > > var o_Date = new Date(); > > o_Requester.url > > o_Requester.url + > > (o_Requester.url.indexOf(''?'') == -1 ? ''?'' : ''&'') + > > ''Stamp='' + o_Date.getTime(); > > if (b_Debug) { console.groupEnd(); } > > }, > > }); > > > > > > -- > > ----- > > Richard Quadling > > Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 > > "Standing on the shoulders of some very clever giants!" > > Thanks very much to you and the clever giants! The following worked > perfectly: > > Ajax.Responders.register({ > onCreate: function(o_Requester){ > // Get fresh variables > var latest = $(''latest'').innerHTML; > o_Requester.url > o_Requester.url + > (o_Requester.url.indexOf(''?'') == -1 ? ''?'' : ''&'') + > ''last='' + latest; > if (b_Debug) { console.groupEnd(); } > } > }); > > This keeps the value of ''latest'' in line with reality over the > lifetime of the updater. > > Thanks again! > > Walter > > > > > >-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2008-Jan-19 17:07 UTC
Re: design pattern help needed for periodical updater
Thanks, I did think about that. In this particular case it''s not an issue. If I was going to do this over, I would manually add the onCreate bit to the affected instance of the PeriodicalUpdater, rather than setting it as a global override for the entire page. I''m sure there''s a clever way to have my cake and eat it too, but this is several levels of abstraction beyond what my feeble procedural brain can conceive of! @Ken -- I thought about your solution, but in the end decided to use Richard''s, because the groovy "decay" feature in PeriodicalUpdater would be useful for this particular application. Better to override the one thing that was vexing me than re-create everything from scratch. Thanks to everyone! Walter PS: here''s the final: http://philadelphiacathedral.org/mandala/gallery.php warning: enormous page, crashes MobileSafari, I really need to also enable an endless scroll of some sort On Jan 19, 2008, at 6:01 AM, Richard Quadling wrote:> > If you have multiple AJAX requests (not repeated ones, but different > ones), then they will ALL get the latest value, so watch out for that. > > > > On 18/01/2008, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> >> >> On Jan 18, 2008, at 10:56 AM, Richard Quadling wrote: >> >>> Justin, I think you missed the bit about this being a periodical >>> updater. The same data is sent each time. >>> >>> Walter, I use the following code to timestamp all my AJAX calls. >>> Makes >>> sure each one is a unique request. Maybe you can adapt it. >>> >>> Ajax.Responders.register >>> ({ >>> onCreate: function(o_Requester) >>> { >>> // Timestamp each AJAX action. >>> var o_Date = new Date(); >>> o_Requester.url >>> o_Requester.url + >>> (o_Requester.url.indexOf(''?'') == -1 ? ''?'' : >>> ''&'') + >>> ''Stamp='' + o_Date.getTime(); >>> if (b_Debug) { console.groupEnd(); } >>> }, >>> }); >>> >>> >>> -- >>> ----- >>> Richard Quadling >>> Zend Certified Engineer : http://zend.com/zce.php? >>> c=ZEND002498&r=213474731 >>> "Standing on the shoulders of some very clever giants!" >> >> Thanks very much to you and the clever giants! The following worked >> perfectly: >> >> Ajax.Responders.register({ >> onCreate: function(o_Requester){ >> // Get fresh variables >> var latest = $(''latest'').innerHTML; >> o_Requester.url >> o_Requester.url + >> (o_Requester.url.indexOf(''?'') == -1 ? >> ''?'' : ''&'') + >> ''last='' + latest; >> if (b_Debug) { console.groupEnd(); } >> } >> }); >> >> This keeps the value of ''latest'' in line with reality over the >> lifetime of the updater. >> >> Thanks again! >> >> Walter >> >> >> >>> >> > > > -- > ----- > Richard Quadling > Zend Certified Engineer : http://zend.com/zce.php? > c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!" > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2008-Jan-19 17:12 UTC
Re: design pattern help needed for periodical updater
Errrr. No sooner do I post this than something goes haywire with the remote camera and it uploads a bunch of really old photos from the original testing, and messes up the modification dates of same. I am really getting tired of driving down to the Cathedral! Walter On Jan 19, 2008, at 12:07 PM, Walter Lee Davis wrote:> PS: here''s the final: > > http://philadelphiacathedral.org/mandala/gallery.php > > warning: enormous page, crashes MobileSafari, I really need to also > enable an endless scroll of some sort--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---