OscarWilde
2007-Nov-27 17:24 UTC
Start and stop the Ajax.PeriodicalUpdater in tow different functions?
Hi, I have a simple function that is called when the user clicks on an "Edit" button: function startEdit(id) { new Ajax.Request(''modules/main.php?action=startEdit&type=ajax&id='' + id, { onSuccess: function(transport) { var observer = new Ajax.PeriodicalUpdater(''time'', ''modules/ main.php?action=activeRecord&type=ajax'', { method: ''get'', frequency: 10 }); } }); } The function copies a record from an DB into a temporary table (via Ajax.Request) and on success it starts the Ajax.PeriodicalUpdater. In a second function I''ve tried to stop this Ajax.PeriodicalUpdater when the user clicks the "Cancel" button but without any success. I''ve tried it this way: function cancelEdit() { observer.stop(); } The "var observer" is no longer present to stop it and the Ajax.PeriodicalUpdater is still running. How can I stop it? Thanks for any tipp! Frank The var oberver is no longer present. --~--~---------~--~----~------------~-------~--~----~ 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-Nov-27 17:42 UTC
Re: Start and stop the Ajax.PeriodicalUpdater in tow different functions?
When, in the first function, you declare "var observer", you are declaring a variable local to the scope of that function. So, dropping the var should work, as you want observer to be a global variable. Best, -Nicolas On Nov 27, 2007 3:24 PM, OscarWilde <mertins-ZMW9gQVgYjrZSx3itfvNfw@public.gmane.org> wrote:> > Hi, > > I have a simple function that is called when the user clicks on an > "Edit" button: > > function startEdit(id) { > new Ajax.Request(''modules/main.php?action=startEdit&type=ajax&id='' + > id, { > onSuccess: function(transport) { > var observer = new Ajax.PeriodicalUpdater(''time'', ''modules/ > main.php?action=activeRecord&type=ajax'', { > method: ''get'', frequency: 10 > }); > } > }); > } > > The function copies a record from an DB into a temporary table (via > Ajax.Request) and on success it starts the Ajax.PeriodicalUpdater. > > In a second function I''ve tried to stop this Ajax.PeriodicalUpdater > when the user clicks the "Cancel" button but without any success. I''ve > tried it this way: > > function cancelEdit() { > observer.stop(); > } > > The "var observer" is no longer present to stop it and the > Ajax.PeriodicalUpdater is still running. How can I stop it? > > Thanks for any tipp! > > Frank > > The var oberver is no longer present. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---