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.
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!-- Posted via http://www.ruby-forum.com/.
Christopher.Preston@csiro.au
2006-Apr-17 23:34 UTC
[Rails] Re: AJAX update of <img> element?
Thanks, that''s what I ended up doing, essentially. It eventually dawned on me that an <img> element has no .value, like a div does, so trying to give it new data was pointless. I ended up having to add another controller action to, as you say, replace the div contents with a new img tag, rather than the contents of the existing img. Chris.> > 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! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >