Join 3,564 readers in helping fund MetaFilter (Hide)


Rails broke my AJAX!
November 12, 2007 7:25 AM   Subscribe

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 Alterscape to Computers & Internet (4 answers total)
 
Is this something we can take a look at?
posted by null terminated at 7:55 AM on November 12, 2007


Would you believe it was a typo I made when I renamed my javascripts and moved them into my Rails app? One of the files is missing an 'i' in the filename, but nothing threw an error I could see until another script tried to invoke a function in that script..

But thank you, Null Terminated. Trying to put together a demo I could show you (I'm a grad student, the live app involves research that I can't discuss until it's published) revealed the problem! :)
posted by Alterscape at 8:19 AM on November 12, 2007


Hey, if you got that demo working, I'd love to see what you've done- it sounds really fascinating...
posted by potch at 8:28 AM on November 12, 2007


Potch, check out NDSL Strand Maps. This is not my project, and not related to my project, but their techniques inspired the architecture of my project -- when you click on certain elements of the SVG, a method is called in the HTML page's javascript that displays a "callout" with more info about the element you clicked on in an absolute-positioned DIV. Because of the way it's all put together, it makes it look like there's dynamic HTML content inside the SVG, which is really hard to do.
posted by Alterscape at 9:51 AM on November 12, 2007


« Older Help me remember (or find) som...   |  Aperture or Lightroom? And do ... Newer »
This thread is closed to new comments.