Wednesday, October 1, 2008

AJAX: is it possible to update the src parameter of an image directly?

Using pure php/javascript without cakephp, I am able to use the
javascript function
=======
document.getElementById("pic").src = imageName;
=======
to update an image (when a button on the web page is clicked). this
results in very smooth image updates.

In CakePHP, I have been able to update the image from an ajax link by
updating the <div> containing the image. ie. by generating the full
<img> tag in the controller to replace the text in the <div>.
Something like this:
=======
echo "<img src='/cakephp/ajax4/img/jpgraph/".$imageName."' />";
=======

Both methods work OK, but the cakephp <div> update results in a
flicker as the div size briefly goes to zero, before it displays the
image (anything below the image moves up briefly to cover the area
where the image was, then moves back down again when the image is
loaded and displayed). I would like to get the smooth image updates of
the javascript function in CakePHP by directly injecting the new image
name into the src parameter of the <img> tag. Is this possible?


Just to give some more background, I am using jpgraph to generate line
plots based on changing data, with time on the x-axis. Each new graph
is an image with a randomly generated filename that I pass back to the
client.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: