I have a ajax request in a function like so: em = function(url) { var percent; new Ajax.Request(url, { method: ''get'', onSuccess: function(transport) { var Bar = $(''emBar''); percent = transport.responseText; Bar.setStyle({ width: percent + ''%'' }); } }); } And then I have another function that has a PeriodicalExecuter that runs the first function. The problem is I can''t figure out how to make it so the first function returns the percent variable so that the PeriodicalExecuter will stop when it hits a certain number. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Perhaps turn that logic around: Rather than giving the value back to the PE and letting it decide whether to stop, you could pass the PE to the request function and have the request decide whether to stop the PE: em = function(url, pe) { var percent; new Ajax.Request(url, { method: ''get'', onSuccess: function(transport) { var Bar = $(''emBar''); percent = transport.responseText; Bar.setStyle({ width: percent + ''%'' }); if (parseInt(percent) > LIMIT) { pe.stop(); } } }); } Alternately, wrap all of this in an object where both the request and the PE are members, and the object has a method used by the success callback to decide whether to stop. Or, of course, use a global. But that would be wrong. :-) FWIW. -- T.J. Crowder tj / crowder software / com On May 28, 6:04 am, PAOEGONVG <marcus1...-FFYn/CNdgSA@public.gmane.org> wrote:> I have a ajax request in a function like so: > > em = function(url) > { > var percent; > new Ajax.Request(url, > { > method: ''get'', > onSuccess: function(transport) > { > var Bar = $(''emBar''); > percent = transport.responseText; > Bar.setStyle({ width: percent + ''%'' }); > } > }); > > } > > And then I have another function that has a PeriodicalExecuter that > runs the first function. > The problem is I can''t figure out how to make it so the first function > returns the percent variable so that the PeriodicalExecuter will stop > when it hits a certain number.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can''t return the response from the outer function because the inner function completes asynchronously. I would probably wrap the PE in some kind of higher-level object, such that a response of 100% stops it from running. I can probably whip up a quick example if you want. On Wed, May 28, 2008 at 12:04 AM, PAOEGONVG <marcus1060-FFYn/CNdgSA@public.gmane.org> wrote:> > I have a ajax request in a function like so: > > em = function(url) > { > var percent; > new Ajax.Request(url, > { > method: ''get'', > onSuccess: function(transport) > { > var Bar = $(''emBar''); > percent = transport.responseText; > Bar.setStyle({ width: percent + ''%'' }); > } > }); > } > > And then I have another function that has a PeriodicalExecuter that > runs the first function. > The problem is I can''t figure out how to make it so the first function > returns the percent variable so that the PeriodicalExecuter will stop > when it hits a certain number.-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---