marco.rizzetto-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-18 08:24 UTC
RE: Javascript and Prototype
I rewrite a new post because the last is damaged. My problem is that I can''t import file js in the new view. I must include all javascript code inside the view. Example: my.js file: coolFunc = function() { // contents } View Code doesn''t work: <script type="text/javascript" src="/webroot/js/my.js"></script> ..... View Code works: coolFunc = function() { // contents } ..... How can I resolve this? Many Thanks Marco On 14 Dic, 18:51, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 14, 2007 7:11 AM, marco.rizze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > <marco.rizze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I use the Ajax function (Ajax.Updater with evalScripts:true) to load > > a view in a div. > > Now in this view I would load an externaljavascriptfile and use it > > inside the view. > > But when I use a function defined inside thejavascriptfile I get an > > error : "the function is not defined" > > Check the documentation at <http://prototypejs.org/api/ajax/updater>; > it describes how to declare functions in external files if you want > them to work with Ajax.Updater. > > In a nutshell, though, you want to do this... > > coolFunc = function() { > // contents > > } > > ... instead of this ... > > function coolFunc() { > // contents > > } > > Hope that helps. > > :Dan Dorman--~--~---------~--~----~------------~-------~--~----~ 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 need to use a server-side include, not a client-side include. How to do this will depend on which server language you are using. On Dec 18, 3:24 am, "marco.rizze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <marco.rizze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I rewrite a new post because the last is damaged. > > My problem is that I can''t import file js in the new view. > I must include all javascript code inside the view. > > Example: > > my.js file: > > coolFunc = function() { > // contents > > } > > View Code doesn''t work: > > <script type="text/javascript" src="/webroot/js/my.js"></script> > > ..... > > View Code works: > > coolFunc = function() { > // contents > > } > > ..... > > How can I resolve this? > Many Thanks > Marco > > On 14 Dic, 18:51, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Dec 14, 2007 7:11 AM, marco.rizze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > > <marco.rizze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I use the Ajax function (Ajax.Updater with evalScripts:true) to load > > > a view in a div. > > > Now in this view I would load an externaljavascriptfile and use it > > > inside the view. > > > But when I use a function defined inside thejavascriptfile I get an > > > error : "the function is not defined" > > > Check the documentation at <http://prototypejs.org/api/ajax/updater>; > > it describes how to declare functions in external files if you want > > them to work with Ajax.Updater. > > > In a nutshell, though, you want to do this... > > > coolFunc = function() { > > // contents > > > } > > > ... instead of this ... > > > function coolFunc() { > > // contents > > > } > > > Hope that helps. > > > :Dan Dorman--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---