Loading non-RJS javascript via ajax in Rails
Posted
by David Smith
on Stack Overflow
See other posts from Stack Overflow
or by David Smith
Published on 2010-05-20T15:44:36Z
Indexed on
2010/05/20
19:10 UTC
Read the original article
Hit count: 239
I've written a rails module that generates some javascript for a google map. As the user makes changes on the webpage, I use observe_field to call back to the server to regenerate the map's javascript (without updating the whole page). I'm having trouble finding a good way to insert the new javascript into the page. I've tried
<div id='my_div_1'>div1</div>
<%=
update_page_tag do |page|
page.replace_html 'my_div_1', "<script>alert('hi');</script>"
end
%>
but it seems that replace_html only works for non-script html. It chokes when the content includes the closing < /script> tag.
Additional information...here is a page that I think is the root of the problem. http://www.wwco.com/~wls/blog/2007/04/25/using-script-in-a-javascript-literal/
© Stack Overflow or respective owner