Hi all, I want to use Ajax.Updater recursively but I am not getting what I would expect. I have a list o values (e.g. [''a'',''b'',''c'']), and I have a function the gets this list of value and an index. Each of this values is a div to update: update([''a'',''b'',''c''], 0); function update(values, index){ Ajax.Updater(values[index], {onComplete:update(values, index+1)}); } Even with asynchrony this code should request a, b, c, right? How can I do this series of requests and updates using the order on the list? Regards, Miguel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ollie a écrit :> function update(values, index){ > Ajax.Updater(values[index], {onComplete:update(values, index+1)}); > }You''re calling update, getting the result (undefined), then using this result as a value for onComplete. This code yields infinite recursion, I guess. You should use an anonymous function, and check for *end of array*. You should also use the new operator properly: function update(values, index) { index = index || 0; if (index >= values.length) return; new Ajax.Updater(values[index], { onComplete: function() { update(values, index + 1); }}); } -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well, unless your pseudo-code below is different from your actual code, you have an error. The Ajax.Updater takes first an element on the screen, then a page on the server to which it connects, and finally an object of preferences and optional settings. Your code below lacks one of the two parameters prior to that object and that may be what''s causing your problem. -- Dash -- Ollie wrote:> Hi all, > > I want to use Ajax.Updater recursively but I am not getting what I > would expect. > > I have a list o values (e.g. [''a'',''b'',''c'']), and I have a function the > gets this list of value and an index. > Each of this values is a div to update: > > update([''a'',''b'',''c''], 0); > > function update(values, index){ > Ajax.Updater(values[index], {onComplete:update(values, index+1)}); > } > > Even with asynchrony this code should request a, b, c, right? > How can I do this series of requests and updates using the order on > the list? > > Regards, > > Miguel > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 a écrit :> Well, unless your pseudo-code below is different from your actual code, > you have an error. The Ajax.Updater takes first an element on the > screen, then a page on the server to which it connects, and finally anD''oh! Hadn''t even noticed that... Indeed, there''s a need for http://prototypejs.org/api/ajax/updater -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I ommited a few things such as recursion control and the url to update from. I apologise for that. The ommited aspects are of course important, but they are not the cause of my problem. update([''a'',''b'',''c''], 0); function update(values, index){ if(values.length <= index) return; Ajax.Updater(values[index], SOME_URL, {onComplete:update(values, index+1)}); } My previous questions still stand. On May 8, 2:04 pm, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> David Dashifen Kees a écrit : > > > Well, unless your pseudo-code below is different from your actual code, > > you have an error. The Ajax.Updater takes first an element on the > > screen, then a page on the server to which it connects, and finally an > > D''oh! Hadn''t even noticed that... > > Indeed, there''s a need forhttp://prototypejs.org/api/ajax/updater > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I ommited a few things such as recursion control and url to update. I apologise for that. These things are important but they are not related to the issue described. New code: update([''a'',''b'',''c''], 0); function update(values, index){ if(values.length >= index) return; Ajax.Updater(values[index], SOME_URL, {onComplete:update(values, index+1)}); } My previous questions still stand: Even with asynchrony this code should request a, b, c, right? How can I do this series of requests and updates using the order on the list? On May 8, 2:04 pm, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> David Dashifen Kees a écrit : > > > Well, unless your pseudo-code below is different from your actual code, > > you have an error. The Ajax.Updater takes first an element on the > > screen, then a page on the server to which it connects, and finally an > > D''oh! Hadn''t even noticed that... > > Indeed, there''s a need forhttp://prototypejs.org/api/ajax/updater > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ollie wrote:> I ommited a few things such as recursion control and the url to update > from. I apologise for that. > The ommited aspects are of course important, but they are not the > cause of my problem. > > update([''a'',''b'',''c''], 0); > > function update(values, index){ > > if(values.length <= index) return; > > Ajax.Updater(values[index], SOME_URL, {onComplete:update(values, > index+1)}); > > }Someone already answered this, but you need to use an anonymous function as the value of onComplete. You are passing it the *return* value of the update() function which means you''re actually executing it before the previous run has finished executing. And you need to use ''new'' since you''re creating a new object. function update(values, index){ if(values.length <= index) return; new Ajax.Updater(values[index], SOME_URL, { onComplete: function() { update(values,index+1)} }); } Now, when currying support makes it into prototype (1.5.2?) you can do something like this: function update(values, index){ if(values.length <= index) return; new Ajax.Updater(values[index], SOME_URL, { onComplete: update.given(values,index+1) }); } -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> My previous questions still stand.No it doesn''t. You didn''t read my reply carefully enough: I explained why your onComplete expression is invalid: you''re calling update immediately (at definition time) instead of within an anonymous callback (at execution time). Check it again. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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''re calling update, getting the result (undefined), then using this > result as a value for onComplete. This code yields infinite recursion, > I guess.I thought that onComplete function was executed after the Ajax request was over. Is this true? Maybe I''m not understanding what you mean. --~--~---------~--~----~------------~-------~--~----~ 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''s it :] Thanks! On May 8, 4:09 pm, Michael Peters <mpet...-aUYv5hkjw45l57MIdRCFDg@public.gmane.org> wrote:> Ollie wrote: > > I ommited a few things such as recursion control and the url to update > > from. I apologise for that. > > The ommited aspects are of course important, but they are not the > > cause of my problem. > > > update([''a'',''b'',''c''], 0); > > > function update(values, index){ > > > if(values.length <= index) return; > > > Ajax.Updater(values[index], SOME_URL, {onComplete:update(values, > > index+1)}); > > > } > > Someone already answered this, but you need to use an anonymous function as the > value of onComplete. You are passing it the *return* value of the update() > function which means you''re actually executing it before the previous run has > finished executing. And you need to use ''new'' since you''re creating a new object. > > function update(values, index){ > > if(values.length <= index) return; > > new Ajax.Updater(values[index], SOME_URL, { > onComplete: function() { update(values,index+1)} > }); > > } > > Now, when currying support makes it into prototype (1.5.2?) you can do something > like this: > > function update(values, index){ > > if(values.length <= index) return; > new Ajax.Updater(values[index], SOME_URL, { > onComplete: update.given(values,index+1) > });} > > -- > Michael Peters > Developer > Plus Three, LP--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Please ignore the previous post. On May 8, 3:54 pm, Ollie <olliega...-d5g5+T9Uxf9Wk0Htik3J/w@public.gmane.org> wrote:> I ommited a few things such as recursion control and url to update. I > apologise for that. > These things are important but they are not related to the issue > described. > > New code: > > update([''a'',''b'',''c''], 0); > > function update(values, index){ > if(values.length >= index) return; > Ajax.Updater(values[index], SOME_URL, {onComplete:update(values, > index+1)}); > > } > > My previous questions still stand: > > Even with asynchrony this code should request a, b, c, right? > How can I do this series of requests and updates using the order on > the list? > > On May 8, 2:04 pm, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote: > > > David Dashifen Kees a écrit : > > > > Well, unless your pseudo-code below is different from your actual code, > > > you have an error. The Ajax.Updater takes first an element on the > > > screen, then a page on the server to which it connects, and finally an > > > D''oh! Hadn''t even noticed that... > > > Indeed, there''s a need forhttp://prototypejs.org/api/ajax/updater > > > -- > > Christophe Porteneuve a.k.a. TDD > > "[They] did not know it was impossible, so they did it." --Mark Twain > > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ollie wrote:>> You''re calling update, getting the result (undefined), then using this >> result as a value for onComplete. This code yields infinite recursion, >> I guess. > > I thought that onComplete function was executed after the Ajax request > was over. > Is this true?It does.> Maybe I''m not understanding what you mean.It seems you aren''t understanding the difference between calling a function and just referring to it. function hello(name) { alert(''hello '' + name) }; hello(''Michael''); // this executes hello var bar = hello; // this just "references" hello onComplete takes a function. you were instead passing it the return value of your update() function which means you were executing it. Since prototype doesn''t yet support currying, if you need to reference a function while passing it arguments you need to instead wrap the call to your function inside of an anonymous function. var bar = function() { hello(''Michael'') }; Unlike some languages (Java, C#) in Javascript functions are objects too. -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---