Re: Returning JS in AJAX

Steve Willer
2005-06-02T21:00:39Z

The problem with Erik''s approach is that it requires user action. What
if you want to unhide a div when an ajax''d page loads?

I was told today, btw, that IFRAME also has an onload feature, even
without a SRC attribute. So potentially you could stick your
javascript in the iframe and put an onload that''s something like
onload="eval(this.innerHTML)". That''s very nearly script
tag-like. I
haven''t tried it yet, though.


On 6/1/05, David Teare
<dteare-LXYvB7aEQDJCkLs28/y7ANBPR1lH4CV8@public.gmane.org>
wrote:
>  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
<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
>
>
>  _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>