Re: Returning JS in AJAX

Steve Willer
2005-06-02T01:38:07Z

The only solution I''ve found for this is to have:

- a div with javascript in it (hidden with css)
- an image with an
onload="eval($(''somediv'').innerHTML)" attribute
(hidden with css)

The on* events trigger, but inline javascript doesn''t. Your javascript
in the div can define function as well as execute them, just like
stuff in a script tag.

Of course, you could always define the script in the enclosing page. :-)

Oh, and make sure the image you''re referencing exists. Otherwise the
onload won''t run.


Steve


On 6/1/05, David Teare
<dteare-LXYvB7aEQDJCkLs28/y7ANBPR1lH4CV8@public.gmane.org>
wrote:
>
> I have Ajax working fine to return html code and display it in a div.
> Now, I would like to return some JavaScript generated in the controller,
> and have this execute in the browser.  I tried assigning the script code
> to a div, which successfully put the script into the div, but the code
> is never executed.
>
> What I would like is something like DWR (http://getahead.ltd.uk/dwr/)
> that allows you to define a JS function that will be executed with the
> returned ajaxed data.  Is this possible in Rails?  I can port over the
> DWR code, but I don''t want to reinvent the wheel.
>
> Thanks!
> --Dave.
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>