Please help me get a Javascript embedded in an SVG talking to a Javascript embedded in an XHTML page, when they're both in a Ruby on Rails RHTML template. Works fine when the HTML page is a flatfile, not so well in RoR.
I'm in the process of building a relatively simple AJAX (well, AJAS) script that loads the contents of an SVG document from a server-generated JSON file via an XMLHTTPRequest -- the page javascript loads the json, parses it into objects, and runs a series of calls on the SVG javascript to draw the proper image. I can't just move the javascript all into the SVG, because there are some other user-interface elements outside the SVG that need to pass data into it later, and the SVG script needs to call functions in the HTML too! I have a prototype built in a HTML flatfile running on an apache server where the functionality works as I want using the "window.funcCall()" function described in the
inter-document communication section of the SVG.org wiki. However, when I move my code into a RoR view, the window.funcCall(data) call generates a javascript "function not found" error in FireBug.
I'm 99% sure that I've properly loaded all the related CSS and javascript files into my Rails application -- javascripts into public/javascripts/, etc. Other javascript functions on the page and in the SVG that don't rely on communication between the two function properly. The only potential issue I see is that I'm inserting the <> tag at the top of my RHTML template, which means the javascript isn't being loaded in the tag, which isn't xhtml compliant..
Any thoughts how to resolve this issue? I know I'm not using 100% correct Rails design patterns, and I do plan to refactor my code to make it more Rails-friendly, but I need to get the basic functionality working ASAP. I never imagined that integrating it into Rails would break things, since a RHTML file is rendered as just another HTML document to the browser?>
posted by null terminated at 7:55 AM on November 12, 2007