ajax image data fetch, javascript IMG data update?

M

Marcus

Here is a toy problem describing what I want to do:

I have a web page with a single IMG element (say for a 128 x 128
"screen") which is initially blank (image=black pixels). I have AJAX
code that polls my server for updated image data. I would like to use
AJAX to fetch the image data, and then use javascript to update the IMG
data to show the new picture. This needs to work in IE and Firefox.

I've seen a few similar posts, but no concrete answers: is this
possible? If so, how?
 
R

Richard Cornford

Marcus said:
Here is a toy problem describing what I want to do:

I have a web page with a single IMG element (say for a 128 x 128
"screen") which is initially blank (image=black pixels). I have AJAX
code that polls my server for updated image data. I would like to use
AJAX to fetch the image data, and then use javascript to update the IMG
data to show the new picture. This needs to work in IE and Firefox.

I've seen a few similar posts, but no concrete answers: is this
possible? If so, how?

It is not possible to provide an IMG element with binary data through
an XML HTTP request.

If it was possible to use a javascript pseudo-protocol URL as the SRC
of an image it may have been possible, but tortuously difficult (issues
with the text response being binary data (originally) interpreted as
UTF-8 into a javascript string of 16 bit code points and then needing
to be translated into a string that can be interpreted by the IMG's SRC
(on Mozilla/Gecko, where this is possible, the sting used is expected
to have a single byte of data in the each character)).

Richard.
 
P

Peter Michaux

Marcus said:
Here is a toy problem describing what I want to do:

I have a web page with a single IMG element (say for a 128 x 128
"screen") which is initially blank (image=black pixels). I have AJAX
code that polls my server for updated image data. I would like to use
AJAX to fetch the image data, and then use javascript to update the IMG
data to show the new picture. This needs to work in IE and Firefox.

I've seen a few similar posts, but no concrete answers: is this
possible? If so, how?

You can use Ajax to poll the server to determine when the image is
ready or what the new URL will be. When the new picture is available
just change the src attribute of the image tag and the browser will
automatically get and update the image.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top