Re: Returning JS in AJAX

David Teare
2005-06-02T02:02:44Z

Wow - that looks complicated!  I would have never thought of that.

Erik''s approach looks much more straight forward.

Steve Willer wrote:

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  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

Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails


_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org