Nasir Khan wrote:> Using RJS is it possible to update the javascript code within the
> <script>
> tag in the <head>?
>
> So what I have done is that I have the <script> wrapped in a
<div>. On a
> certain action I use RJS to update that
> <div> using page.replace_html.
>
> The logs show that the <div> actually gets replaced, but the new
> javascript
> does not take effect.
>
> The div -
>
> <div id="replaceable_js">
> <script>
> var = "hello";
> </sctript>
> </div>
RJS should not replace the javascript in a div to be executed, because
RJS is javascript being executed in the first place. Simply execute
your javascript in your RJS template and leave writing script tags to
the DOM out of it completely.
When responding to AJAX calls with HTML and not javascript, it will by
default look for <script> tags and execute them. The same is not true
if the response is javascript since it is already execute a script and
wont scan the DOM for script tags again.
## rjs_example.rjs
page[''something''].visual_effect :highlight
page << ''var = "hello";''
Writing a script tag with javascript is just silly if you want it to
execute immediately. Remember that RJS will execute on the page it''s
called from, even though it''s a new request since the javascript it
generates doesn''t execute until it''s arrived on the page that
requested
it.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---