Max Pagels
2007-Oct-22 12:32 UTC
Question about Prototype: javascript code in the response
Hi, I''m making a web apps for school and trying to incorporate some AJAX using PHP and Prototype. I''ve run into a problem: how to immediately run javascript code that is in the response of an Ajax request. On my start page of my web app, i have the code <script type="text/javascript"> new Ajax.Updater(''login'', ''login.php'', {evalScripts:true}); </script> now, login php returns some HTML code and the javascript code: <script type="text/javascript"> new Ajax.Updater(''adddrink'', ''adddrink.php''); </script> I would like for this snippet of javascript code to run immendiately after it''s been received, but I can''t figure out how this should be done. The code I''ve written doesn''t seem to have any errors, and the response does contain the javascript code (I checked). Any ideas? P.S. Do excuse my poor english. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Max Pagels
2007-Oct-22 12:35 UTC
Re: Question about Prototype: javascript code in the response
I forgot to mention that a reload of the page executes the javascript as expected. On Oct 22, 3:32 pm, Max Pagels <max.page...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m making a web apps for school and trying to incorporate some AJAX > using PHP and Prototype. I''ve run into a problem: how to immediately > run javascript code that is in the response of an Ajax request. > > On my start page of my web app, i have the code > > <script type="text/javascript"> > new Ajax.Updater(''login'', ''login.php'', {evalScripts:true}); > </script> > > now, login php returns some HTML code and the javascript code: > > <script type="text/javascript"> > new Ajax.Updater(''adddrink'', ''adddrink.php''); > </script> > > I would like for this snippet of javascript code to run immendiately > after it''s been received, but I can''t figure out how this should be > done. > > The code I''ve written doesn''t seem to have any errors, and the > response does contain the javascript code (I checked). Any ideas? > > P.S. Do excuse my poor english.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Diodeus
2007-Oct-22 19:28 UTC
Re: Question about Prototype: javascript code in the response
If you''re going to be running the same code after the response, then you might was well use the onComplete event to call a function to perform he second updater instead of sending it back in the response. <script type="text/javascript"> new Ajax.Updater(''login'', ''login.php'', onSuccess: function() {addDrink()}, {evalScripts:true}); </script> On Oct 22, 8:35 am, Max Pagels <max.page...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I forgot to mention that a reload of the page executes the javascript > as expected. > > On Oct 22, 3:32 pm, Max Pagels <max.page...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I''m making a web apps for school and trying to incorporate some AJAX > > using PHP and Prototype. I''ve run into a problem: how to immediately > > run javascript code that is in the response of an Ajax request. > > > On my start page of my web app, i have the code > > > <script type="text/javascript"> > > new Ajax.Updater(''login'', ''login.php'', {evalScripts:true}); > > </script> > > > now, login php returns some HTML code and the javascript code: > > > <script type="text/javascript"> > > new Ajax.Updater(''adddrink'', ''adddrink.php''); > > </script> > > > I would like for this snippet of javascript code to run immendiately > > after it''s been received, but I can''t figure out how this should be > > done. > > > The code I''ve written doesn''t seem to have any errors, and the > > response does contain the javascript code (I checked). Any ideas? > > > P.S. Do excuse my poor english.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---