ajax image data fetch, javascript IMG data update?

Discussion in 'Javascript' started by Marcus, Dec 8, 2006.

  1. Marcus

    Marcus Guest

    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?
     
    Marcus, Dec 8, 2006
    #1
    1. Advertising

  2. Marcus wrote:
    > 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.
     
    Richard Cornford, Dec 8, 2006
    #2
    1. Advertising

  3. Marcus wrote:
    > 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
     
    Peter Michaux, Dec 8, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.austin.rr.com

    how to download img from html img tag

    news.austin.rr.com, Apr 27, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    523
    Steve C. Orr [MVP, MCSD]
    Apr 27, 2005
  2. Philipp Lenssen

    Problem: <img></img>

    Philipp Lenssen, Jun 27, 2005, in forum: XML
    Replies:
    15
    Views:
    778
    David Håsäther
    Jul 3, 2005
  3. Jopek
    Replies:
    7
    Views:
    412
    dorayme
    Apr 26, 2009
  4. Biranchi Narayan Panda
    Replies:
    0
    Views:
    565
    Biranchi Narayan Panda
    Feb 21, 2010
  5. Replies:
    7
    Views:
    193
    Tad McClellan
    Jun 22, 2006
Loading...

Share This Page