Forum: Ruby on Rails AJAX update of <img> element?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A419b50c5a6b2aadd0ebe7d13d4b264e?d=identicon&s=25 unknown (Guest)
on 2006-04-16 05:32
(Received via mailing list)
Hi,

I've been trying to do AJAX updates of an <img> element, but I can't
seem to make it work.

Should it be possible to do something like this...?

[View]
<%= form_remote_tag :url => {:action => 'sendplot'}, :update => 'plot'
%>
<%= submit_tag %>
<%= end_form_tag %>
<img id="plot" src="someimage.png"/>

[Controller]
def sendplot
 output_plot(...) # this sends a png file to the browser - this bit
works
end

I find that the browser (Opera or Firefox), no matter what, won't
:update an existing <img> tag. If I :update a <div> instead, I see the
png data dumped as ascii, but that isn't very useful!

Thanks,
Chris.
34f5b045aec62235c17458650ea75353?d=identicon&s=25 Steve Koppelman (hatless)
on 2006-04-16 13:45
If you want to replace an image and you're updating the <div>, return a
new img tag, not an image file.

unknown wrote:
> I've been trying to do AJAX updates of an <img> element, but I can't
> seem to make it work.
>
> Should it be possible to do something like this...?
>
> [View]
> <%= form_remote_tag :url => {:action => 'sendplot'}, :update => 'plot'
> %>
> <%= submit_tag %>
> <%= end_form_tag %>
> <img id="plot" src="someimage.png"/>
>
> [Controller]
> def sendplot
>  output_plot(...) # this sends a png file to the browser - this bit
> works
> end
>
> I find that the browser (Opera or Firefox), no matter what, won't
> :update an existing <img> tag. If I :update a <div> instead, I see the
> png data dumped as ascii, but that isn't very useful!
This topic is locked and can not be replied to.