Geoff
2007-Dec-30 16:41 UTC
Ajax.PeriodicalUpdater: stopping previous call when making a new call
So, I''ve been working on a page to update previous calls with new calls when click on certain lnks. For example: <a href="onClick=''new Ajax.PeriodicalUpdater{method: get, index.php? page=1, frequency: 300, decay 300 }''>Home</a> <a href="onClick=''new Ajax.PeriodicalUpdater{method: get, index.php? page=2, frequency: 300, decay 300 }''>Articles</a> I click on the Home link, it updates fine BUT when I click on the Articles link, that info is pulled as well in addition to the info that was pulled when clicking the Home link too. So, it''s rotating between both. What could I do to stop the first ajax call when I click on a second click to make a new ajax call? Any help is greatly appreciated. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nicolás Sanguinetti
2007-Dec-30 20:18 UTC
Re: Ajax.PeriodicalUpdater: stopping previous call when making a new call
Well, first of all, clean up the code and don''t use inline event handlers, logic is much more difficult to add there :) I''d do something like this: document.observe("dom:loaded", function() { var updater; $$(".navigation_link").invoke("observe", "click", function(event) { event.stop(); if (updater) updater.stop(); updater = new Ajax.PeriodicalUpdater(this.readAttribute("href"), { method: "get", ... }); }); }); And change the html to something like <a href="index.php?page=1" class="navigation_link">Home</a> <a href="index.php?page=2" class="navigation_link">Articles</a> This way, if javascript if disabled, the link will be followed anyway and your users won''t be stuck in the current page :) Best, -Nicolas On Dec 30, 2007 2:41 PM, Geoff <vg32et-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > So, I''ve been working on a page to update previous calls with new > calls when click on certain lnks. > For example: > > <a href="onClick=''new Ajax.PeriodicalUpdater{method: get, index.php? > page=1, frequency: 300, decay 300 }''>Home</a> > <a href="onClick=''new Ajax.PeriodicalUpdater{method: get, index.php? > page=2, frequency: 300, decay 300 }''>Articles</a> > > I click on the Home link, it updates fine BUT when I click on the > Articles link, that info is pulled as well in addition to the info > that was pulled when clicking the Home link too. So, it''s rotating > between both. > > What could I do to stop the first ajax call when I click on a second > click to make a new ajax call? Any help is greatly appreciated. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Geoff
2007-Dec-30 22:18 UTC
Re: Ajax.PeriodicalUpdater: stopping previous call when making a new call
Didn''t work. It''s only directing me to a new page and not calling the info within the current page On Dec 30, 3:18 pm, "Nicolás Sanguinetti" <godf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, first of all, clean up the code and don''t use inline event > handlers, logic is much more difficult to add there :) > I''d do something like this: > > document.observe("dom:loaded", function() { > var updater; > $$(".navigation_link").invoke("observe", "click", function(event) { > event.stop(); > if (updater) updater.stop(); > updater = new Ajax.PeriodicalUpdater(this.readAttribute("href"), { > method: "get", ... }); > }); > > }); > > And change the html to something like > > <a href="index.php?page=1" class="navigation_link">Home</a> > <a href="index.php?page=2" class="navigation_link">Articles</a> > > This way, if javascript if disabled, the link will be followed anyway > and your users won''t be stuck in the current page :) > > Best, > -Nicolas > > On Dec 30, 2007 2:41 PM, Geoff <vg3...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > So, I''ve been working on a page to update previous calls with new > > calls when click on certain lnks. > > For example: > > > <a href="onClick=''new Ajax.PeriodicalUpdater{method: get, index.php? > > page=1, frequency: 300, decay 300 }''>Home</a> > > <a href="onClick=''new Ajax.PeriodicalUpdater{method: get, index.php? > > page=2, frequency: 300, decay 300 }''>Articles</a> > > > I click on the Home link, it updates fine BUT when I click on the > > Articles link, that info is pulled as well in addition to the info > > that was pulled when clicking the Home link too. So, it''s rotating > > between both. > > > What could I do to stop the first ajax call when I click on a second > > click to make a new ajax call? Any help is greatly appreciated.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---