Hello, i try this getDaySum: function() { var elements = $$(''[id^="daysum["]''); var vars = ""; var datum = ""; for (i = 0; i < elements.length; i++) { datum = elements[i].id.substring(7,17); vars = ''&datum='' + datum; new Ajax.Request(''index.php?m=arbeitszeiten&c=getTagessumme''+vars, { evalScripts:true, onSuccess: function(transport) { var response = transport.responseText; $(''daysum[''+datum+'']'').innerHTML = response; //alert("Success! \n\n" + response); } , onFailure: function(){ alert(''Die Verbindung zum Server ist unterbrochen!'') } }); } }, the problem is, when get the onsuccess the "datum" var is on the last iteration value. how can i give the onsuccess the "datum" ____________ Virus checked by G DATA AntiVirusKit Version: AVK 18.497 from 10.11.2007 Virus news: www.antiviruslab.com --~--~---------~--~----~------------~-------~--~----~ 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 would do it something like this: if (i == (elements.length - 1)) alert(datum); Not sure if I understood your question, but I thought you meant something like this. Greetz On Nov 10, 7:09 pm, "reta...-Mmb7MZpHnFY@public.gmane.org" <reta...-Mmb7MZpHnFY@public.gmane.org> wrote:> Hello, > > i try this > > getDaySum: function() > { > var elements = $$(''[id^="daysum["]''); > var vars = ""; > var datum = ""; > for (i = 0; i < elements.length; i++) > { > datum = elements[i].id.substring(7,17); > vars = ''&datum='' + datum; > > new Ajax.Request(''index.php?m=arbeitszeiten&c=getTagessumme''+vars, > { > evalScripts:true, > onSuccess: function(transport) > { > var response = transport.responseText; > $(''daysum[''+datum+'']'').innerHTML = response; > //alert("Success! \n\n" + response); > } , > onFailure: function(){ alert(''Die Verbindung zum Server ist > unterbrochen!'') } > }); > } > > }, > > the problem is, when get the onsuccess the "datum" var is on the last > iteration value. how can i give the onsuccess the "datum" > > ____________ > Virus checked by G DATA AntiVirusKit > Version: AVK 18.497 from 10.11.2007 > Virus news:www.antiviruslab.com--~--~---------~--~----~------------~-------~--~----~ 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 believe you need some sort of closure. Try using curry. Here''s an untested piece of code that might do what you need: onSuccess: (function(datum, transport) { // your code }).curry(datum); retacom-Mmb7MZpHnFY@public.gmane.org wrote:> Hello, > > i try this > > getDaySum: function() > { > var elements = $$(''[id^="daysum["]''); > var vars = ""; > var datum = ""; > for (i = 0; i < elements.length; i++) > { > datum = elements[i].id.substring(7,17); > vars = ''&datum='' + datum; > > new Ajax.Request(''index.php?m=arbeitszeiten&c=getTagessumme''+vars, > { > evalScripts:true, > onSuccess: function(transport) > { > var response = transport.responseText; > $(''daysum[''+datum+'']'').innerHTML = response; > //alert("Success! \n\n" + response); > } , > onFailure: function(){ alert(''Die Verbindung zum Server ist > unterbrochen!'') } > }); > } > > }, > > > the problem is, when get the onsuccess the "datum" var is on the last > iteration value. how can i give the onsuccess the "datum" > > ____________ > Virus checked by G DATA AntiVirusKit > Version: AVK 18.497 from 10.11.2007 > Virus news: www.antiviruslab.com > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 11, 4:09 am, "reta...-Mmb7MZpHnFY@public.gmane.org" <reta...-Mmb7MZpHnFY@public.gmane.org> wrote:> Hello, > > i try this > > getDaySum: function() > { > var elements = $$(''[id^="daysum["]''); > var vars = ""; > var datum = "";Here datum is declared as a local variable of the anonymous function assigned as the value of the getDaySum property.> for (i = 0; i < elements.length; i++) > { > datum = elements[i].id.substring(7,17);Here you set the value of datum on each loop.> vars = ''&datum='' + datum; > > new Ajax.Request(''index.php?m=arbeitszeiten&c=getTagessumme''+vars, > { > evalScripts:true, > onSuccess: function(transport)The function assigned to the value of the onSuccess property has all the "outer" function''s variables on its scope chain, so...> { > var response = transport.responseText; > $(''daysum[''+datum+'']'').innerHTML = response;...here datum is a reference to the datum you declared above - you have a closure. All your onSuccess anonymous functions reference the same datum variable, so they all get the same value at any given time. You need to break the closure, try something like: onSuccess: (function(datum) { return function(transport) { var response = transport.responseText; $(''daysum['' + datum + '']'').innerHTML = response; } })(datum), -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---