Hi, i wish to run a function that came inside my Ajax response. I read that i have to use the evalScripts to make this, but still i couldn''t make it work. The error said that my function isn''t declared. I look at the Sergio Pereira tutorial about use the var xxx = function() but still doesn''t work. Someone could help me? In the response this is the code: for (var i = 0; i < 632; i++) { if (document.newsStoriesForm[''storyIDs'' + i]) { t.newsFeeds[0]["storyIDs"][i] = document.newsStoriesForm[''storyIDs'' + i].value; t.newsFeeds[0]["stories"][i] = document.newsStoriesForm[''stories'' +i].value; } } t.av(''0'', ''632''); ultima2(){ var ultimaNoticia =632; $(''lastStory'').innerHTML = ultimaNoticia; } And this is the Request function: var consultaAjax = new Ajax.Updater ( ''tabla'', url, { method: ''get'', parameters: pars, evalScripts: true, }); } Thanks
I would kill the comma after the true. Not sure if this is an issue, but evalscripts works all the time for us! Deco On Mar 21, 2006, at 1:00 PM, Guillermo Movia wrote:> Hi, i wish to run a function that came inside my Ajax response. I read > that i have to use the evalScripts to make this, but still i couldn''t > make it work. The error said that my function isn''t declared. I look > at the Sergio Pereira tutorial about use the var xxx = function() but > still doesn''t work. > > Someone could help me? > > In the response this is the code: > > for (var i = 0; i < 632; i++) { > if (document.newsStoriesForm[''storyIDs'' + i]) { > t.newsFeeds[0]["storyIDs"][i] = document.newsStoriesForm[''storyIDs'' > + i].value; > t.newsFeeds[0]["stories"][i] = document.newsStoriesForm[''stories'' > +i].value; > } > } > t.av(''0'', ''632''); > ultima2(){ > var ultimaNoticia =632; > $(''lastStory'').innerHTML = ultimaNoticia; > } > > And this is the Request function: > > var consultaAjax = new Ajax.Updater ( > ''tabla'', > url, > { > method: ''get'', > parameters: pars, > evalScripts: true, > }); > } > > Thanks > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> I would kill the comma after the true. Not sure if this is an issue, > but evalscripts works all the time for us!Yes, it is an issue in IE. IE thinks it''s a syntax error. Greg
Thanks for the answers, but It isn''t work yet. This is the code in the ajax response. Before this, the response has a code for an html table (i don''t know if i could mix javascript code and html) ultima2 = function() { var ultimaNoticia = 677; $(''lastStory'').innerHTML = ultimaNoticia; }; </script> <input type=button value=''Apretar'' onclick=''ultima2()'' /> Now, my ajax call says: var consultaAjax = new Ajax.Updater ( ''tabla'', url, { method: ''get'', parameters: pars, evalScripts: true }); } But when i press the button, it said ultima2 is not declared. Which thing i am making bad. Thanks Guillermo
Does your response have <script> tags around the script? evalScripts looks for that and runs any code inside <script> tags. It doesn''t just blindly eval the whole block. You should be able to also have html markup in the response. Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Guillermo Movia > Sent: Tuesday, March 21, 2006 2:34 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] Javascript Code inside an Ajax response > > Thanks for the answers, but It isn''t work yet. This is the code in the > ajax response. Before this, the response has a code for an html table > (i don''t know if i could mix javascript code and html) > > ultima2 = function() { > var ultimaNoticia = 677; > $(''lastStory'').innerHTML = ultimaNoticia; > }; > </script> > <input type=button value=''Apretar'' onclick=''ultima2()'' /> > > Now, my ajax call says: > > var consultaAjax = new Ajax.Updater ( > ''tabla'', > url, > { > method: ''get'', > parameters: pars, > evalScripts: true > }); > } > > But when i press the button, it said ultima2 is not declared. Which > thing i am making bad. > Thanks > > Guillermo > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
It looks like it is not recognizing the calling function "utlima2" Also the utima2 never calls the Ajax.Updater?? Deco The pr On Mar 21, 2006, at 2:40 PM, Gregory Hill wrote:> Does your response have <script> tags around the script? evalScripts > looks for that and runs any code inside <script> tags. It doesn''t > just > blindly eval the whole block. You should be able to also have html > markup in the response. > > Greg > >> -----Original Message----- >> From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs- >> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Guillermo Movia >> Sent: Tuesday, March 21, 2006 2:34 PM >> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> Subject: Re: [Rails-spinoffs] Javascript Code inside an Ajax response >> >> Thanks for the answers, but It isn''t work yet. This is the code in >> the >> ajax response. Before this, the response has a code for an html table >> (i don''t know if i could mix javascript code and html) >> >> ultima2 = function() { >> var ultimaNoticia = 677; >> $(''lastStory'').innerHTML = ultimaNoticia; >> }; >> </script> >> <input type=button value=''Apretar'' onclick=''ultima2()'' /> >> >> Now, my ajax call says: >> >> var consultaAjax = new Ajax.Updater ( >> ''tabla'', >> url, >> { >> method: ''get'', >> parameters: pars, >> evalScripts: true >> }); >> } >> >> But when i press the button, it said ultima2 is not declared. Which >> thing i am making bad. >> Thanks >> >> Guillermo >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Thanks, Greg, yes the script has the script tag before: <script> for (var i = 0; i < 677; i++) { if (document.newsStoriesForm[''storyIDs'' + i]) { t.newsFeeds[0]["storyIDs"][i] = document.newsStoriesForm[''storyIDs'' + i].value; t.newsFeeds[0]["stories"][i] = document.newsStoriesForm[''stories'' +i].value; } } t.av(''0'', ''677''); ultima2 = function() { var ultimaNoticia = 677; $(''lastStory'').innerHTML = ultimaNoticia; }; </script> This is the complete part of the script. The response has three differents blocks of script, evalScripts search for all or just the first or last? Guillermo 2006/3/21, Gregory Hill <Gregory_Hill-l9nu40+TWxQ@public.gmane.org>:> Does your response have <script> tags around the script? evalScripts > looks for that and runs any code inside <script> tags. It doesn''t just > blindly eval the whole block. You should be able to also have html > markup in the response. > > Greg > > > -----Original Message----- > > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs- > > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Guillermo Movia > > Sent: Tuesday, March 21, 2006 2:34 PM > > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > Subject: Re: [Rails-spinoffs] Javascript Code inside an Ajax response > > > > Thanks for the answers, but It isn''t work yet. This is the code in the > > ajax response. Before this, the response has a code for an html table > > (i don''t know if i could mix javascript code and html) > > > > ultima2 = function() { > > var ultimaNoticia = 677; > > $(''lastStory'').innerHTML = ultimaNoticia; > > }; > > </script> > > <input type=button value=''Apretar'' onclick=''ultima2()'' /> > > > > Now, my ajax call says: > > > > var consultaAjax = new Ajax.Updater ( > > ''tabla'', > > url, > > { > > method: ''get'', > > parameters: pars, > > evalScripts: true > > }); > > } > > > > But when i press the button, it said ultima2 is not declared. Which > > thing i am making bad. > > Thanks > > > > Guillermo > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
No, ultima2() doesn''t call the Ajax.Updater, it comes in the response, but nothing else. The button also came in the response. Which is the way to use this function? Guillermo 2006/3/21, Deco Rior <decorior-w9xKMqPX1QdNhnlO7+U8Og@public.gmane.org>:> It looks like it is not recognizing the calling function "utlima2" > > Also the utima2 never calls the Ajax.Updater?? > > Deco > > The pr > On Mar 21, 2006, at 2:40 PM, Gregory Hill wrote: > > > Does your response have <script> tags around the script? evalScripts > > looks for that and runs any code inside <script> tags. It doesn''t > > just > > blindly eval the whole block. You should be able to also have html > > markup in the response. > > > > Greg > > > >> -----Original Message----- > >> From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > [mailto:rails-spinoffs- > >> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Guillermo Movia > >> Sent: Tuesday, March 21, 2006 2:34 PM > >> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> Subject: Re: [Rails-spinoffs] Javascript Code inside an Ajax response > >> > >> Thanks for the answers, but It isn''t work yet. This is the code in > >> the > >> ajax response. Before this, the response has a code for an html table > >> (i don''t know if i could mix javascript code and html) > >> > >> ultima2 = function() { > >> var ultimaNoticia = 677; > >> $(''lastStory'').innerHTML = ultimaNoticia; > >> }; > >> </script> > >> <input type=button value=''Apretar'' onclick=''ultima2()'' /> > >> > >> Now, my ajax call says: > >> > >> var consultaAjax = new Ajax.Updater ( > >> ''tabla'', > >> url, > >> { > >> method: ''get'', > >> parameters: pars, > >> evalScripts: true > >> }); > >> } > >> > >> But when i press the button, it said ultima2 is not declared. Which > >> thing i am making bad. > >> Thanks > >> > >> Guillermo > >> _______________________________________________ > >> Rails-spinoffs mailing list > >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
> No, ultima2() doesn''t call the Ajax.Updater, it comes in the response, > but nothing else. The button also came in the response. > Which is the way to use this function?Is ultima2 used by other elements as well? If not, just do an inline function: onclick="function () { ... }" Greg
On 3/21/06, Guillermo Movia <guillermo.movia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ultima2 = function() { > var ultimaNoticia = 677; > $(''lastStory'').innerHTML = ultimaNoticia; > };Try window.ultima2 = function() { ... } Todd
Sorry I misread... Even though I understand what Greg says it should work. Personally, I never use onclick. Instead I use Event.observe Have you tried this: onclick="alert(''test'')"; to see if this works first? On Mar 21, 2006, at 2:55 PM, Guillermo Movia wrote:> No, ultima2() doesn''t call the Ajax.Updater, it comes in the response, > but nothing else. The button also came in the response. > Which is the way to use this function? > > Guillermo > > 2006/3/21, Deco Rior <decorior-w9xKMqPX1QdNhnlO7+U8Og@public.gmane.org>: >> It looks like it is not recognizing the calling function "utlima2" >> >> Also the utima2 never calls the Ajax.Updater?? >> >> Deco >> >> The pr >> On Mar 21, 2006, at 2:40 PM, Gregory Hill wrote: >> >>> Does your response have <script> tags around the script? >>> evalScripts >>> looks for that and runs any code inside <script> tags. It doesn''t >>> just >>> blindly eval the whole block. You should be able to also have html >>> markup in the response. >>> >>> Greg >>> >>>> -----Original Message----- >>>> From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> [mailto:rails-spinoffs- >>>> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Guillermo Movia >>>> Sent: Tuesday, March 21, 2006 2:34 PM >>>> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> Subject: Re: [Rails-spinoffs] Javascript Code inside an Ajax >>>> response >>>> >>>> Thanks for the answers, but It isn''t work yet. This is the code in >>>> the >>>> ajax response. Before this, the response has a code for an html >>>> table >>>> (i don''t know if i could mix javascript code and html) >>>> >>>> ultima2 = function() { >>>> var ultimaNoticia = 677; >>>> $(''lastStory'').innerHTML = ultimaNoticia; >>>> }; >>>> </script> >>>> <input type=button value=''Apretar'' onclick=''ultima2()'' /> >>>> >>>> Now, my ajax call says: >>>> >>>> var consultaAjax = new Ajax.Updater ( >>>> ''tabla'', >>>> url, >>>> { >>>> method: ''get'', >>>> parameters: pars, >>>> evalScripts: true >>>> }); >>>> } >>>> >>>> But when i press the button, it said ultima2 is not declared. Which >>>> thing i am making bad. >>>> Thanks >>>> >>>> Guillermo >>>> _______________________________________________ >>>> Rails-spinoffs mailing list >>>> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >>> _______________________________________________ >>> Rails-spinoffs mailing list >>> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
why are you not using function ultima2(){ } no semicolon at the end On Mar 21, 2006, at 3:08 PM, Todd Ross wrote:> On 3/21/06, Guillermo Movia <guillermo.movia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> ultima2 = function() { >> var ultimaNoticia = 677; >> $(''lastStory'').innerHTML = ultimaNoticia; >> }; > > Try > > window.ultima2 = function() { > ... > } > > Todd > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
I think that is better is i explain my project: I have a php script that return a table with news. To actualize this news, i need the lastID that i bring in the previous call and a number (this variable ultimaNoticia). The lastID was easy for me, because it came like a part of the tr tag, but this last number is more difficult. I think that writing this variable to a invisible div is the better choice, then i am trying to put this variable in a div. Now i am using a button, to try it, but later i want that this thing happen without interaction from the user. (sorry for my english) I don''t know if this is the best way to make it, but it''s something that, like a novice, i think i could make :) Thanks Guillermo
I could make another simple script works with evalScript. Something is wrong with the amount of Javascript i had. I will continue searching for the error. Thanks a lot to all. Guillermo 2006/3/21, Guillermo Movia <guillermo.movia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> I think that is better is i explain my project: > > I have a php script that return a table with news. To actualize this > news, i need the lastID that i bring in the previous call and a number > (this variable ultimaNoticia). The lastID was easy for me, because it > came like a part of the tr tag, but this last number is more > difficult. I think that writing this variable to a invisible div is > the better choice, then i am trying to put this variable in a div. Now > i am using a button, to try it, but later i want that this thing > happen without interaction from the user. (sorry for my english) > > I don''t know if this is the best way to make it, but it''s something > that, like a novice, i think i could make :) > > Thanks > Guillermo >
I don''t know where is the error. If i just make a file with the script taht generate the php and save it like html, it''s work. But with the same script generate by the php, doesnt work. How could i make that ultima2 function runs automatically when the Ajax.response ends? Maybe the problem was the button code. Guillermo
Thanks to all for your help. At last, i could make it work, banning all other scripts of java of the response. Maybe something was wrong there. Guillermo 2006/3/21, Guillermo Movia <guillermo.movia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> I don''t know where is the error. If i just make a file with the script > taht generate the php and save it like html, it''s work. But with the > same script generate by the php, doesnt work. > > How could i make that ultima2 function runs automatically when the > Ajax.response ends? > > Maybe the problem was the button code. > > Guillermo >
Sounds to me like one of your other scripts had an error in it causing the follow-on text to fail. It happens! Deco On Mar 21, 2006, at 8:22 PM, Guillermo Movia wrote:> Thanks to all for your help. At last, i could make it work, banning > all other scripts of java of the response. Maybe something was wrong > there. > > Guillermo > > 2006/3/21, Guillermo Movia <guillermo.movia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> I don''t know where is the error. If i just make a file with the >> script >> taht generate the php and save it like html, it''s work. But with the >> same script generate by the php, doesnt work. >> >> How could i make that ultima2 function runs automatically when the >> Ajax.response ends? >> >> Maybe the problem was the button code. >> >> Guillermo >> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs