san
2007-May-16 02:53 UTC
Event.observe is not recognized over dynamic JS loading via src attribute
Hi,
I have a javascript file built on top of prototype. The first line
says
Event.observe(''window'', ''load'',
''init'')
I loaded this JS via: <script src="file.js"></script>.
However, I have
a need to load this JS file dynamically based on some variables. For a
first attempt, I added this line somewhere in the file:
//__DATE__
I then changed the src in the <script> to:
<script src="/?page=js&date=today"></script> and
expected that the
now changed js will be loaded. It did load, and __DATE__ was replaced
by some date string. The problem is I kept getting error on the JS
console (Firefox 2.0) saying that "Event.observe is not a function".
When printing out the js code from the program, I used various mime
type, namely application/x-javascript, text/javascript, text/plain.
All of this sent the js code to the browser and I can view the JS
source code via View Source. But the ''not a function'' error
mesage is
so stubborn. I even tried it without content-type header at all which
caused error for lack of proper HTTP header.
Any insight why this is happening and how to fix it? If there are some
resources out there, please point me to the right direction. I found
so many results from I google I had problem to narrow them down.
TIA,
san
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
tobie
2007-May-16 04:35 UTC
Re: Event.observe is not recognized over dynamic JS loading via src attribute
I''m not exactly sure what you are trying to do but: 1. make sure thet Prototype is included before your own JS file is, 2. note that Event.observe takes a function as it''s third argument, not a string. Hope this helps, Tobie --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
siege.107th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-16 05:23 UTC
Re: Event.observe is not recognized over dynamic JS loading via src attribute
You could call me crazy, but isn''t the "window" part in your
observe
function supposed to be an element instead of a string?
Event.observe(window, ''load'', ''init'')
On 16 mei, 04:53, san <has...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> I have a javascript file built on top of prototype. The first line
> says
>
> Event.observe(''window'', ''load'',
''init'')
>
> I loaded this JS via: <script
src="file.js"></script>. However, I have
> a need to load this JS file dynamically based on some variables. For a
> first attempt, I added this line somewhere in the file:
>
> //__DATE__
>
> I then changed the src in the <script> to:
>
> <script src="/?page=js&date=today"></script>
and expected that the
> now changed js will be loaded. It did load, and __DATE__ was replaced
> by some date string. The problem is I kept getting error on the JS
> console (Firefox 2.0) saying that "Event.observe is not a
function".
> When printing out the js code from the program, I used various mime
> type, namely application/x-javascript, text/javascript, text/plain.
> All of this sent the js code to the browser and I can view the JS
> source code via View Source. But the ''not a function''
error mesage is
> so stubborn. I even tried it without content-type header at all which
> caused error for lack of proper HTTP header.
>
> Any insight why this is happening and how to fix it? If there are some
> resources out there, please point me to the right direction. I found
> so many results from I google I had problem to narrow them down.
>
> TIA,
> san
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
tobie
2007-May-16 05:26 UTC
Re: Event.observe is not recognized over dynamic JS loading via src attribute
> You could call me crazy, but isn''t the "window" part in your observe > function supposed to be an element instead of a string? > > Event.observe(window, ''load'', ''init'')Right on...! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---