Having problem to get GIF file through XMLHttpRequest

Discussion in 'Javascript' started by willie, Sep 23, 2005.

  1. willie

    willie Guest

    hi dear committee here,
    Recently I am trying to writing a widget with will request a gif file
    from the server. I have done most of the work and the server now is
    sending back the gif file with the following header:

    Server: Microsoft-IIS/5.0 Cache-Control: private Date: Fri, 23 Sep 2005
    13:16:29 GMT Content-Length: 154 Content-Type: image/gif Via: 1.1
    zproxy (NetCache NetApp/5.5R3D2)

    However, when I use the code below to set the image to correscponding
    element, it just doesn't show:
    //code to set gif to image element
    document.getElementById("spamcode").src = req.responseText;

    I have tried to view the responseText in a div area using the
    following code:
    //show content of sent back gif file
    document.getElementById("indicator").innerHTML = req. responseText();

    and it simply give me a string like this:
    GIF89a ñÿÿÿÿÿÿ!ù,
    k"(¢D%JQ¢D€J(¢DˆB"Q"DJ(P¢@‰%B"Q"Dˆ!J,,(P¢@‰J(Q
    Dˆ! P"D‰J(Q¢@‰% "Q"D‰!JP¢D€U;

    I am quite new to javascript and just get my hand on the
    XMLHttpRequest. Tried a lot of method like:
    document.getElementById("spamcode").src =
    "data:image/gif,base64;"+req.responseText;
    But still, I am no lucky.

    I am not sure whether it is because of the decoding problem because I
    searched the web and the GIF89a file content always shows like
    GIF89a\1\0\1\0\200[...]\1\0;

    Hope you exports could give me some way to solve this problem,
    anyway, school final exam is coming..

    regards,
    Liao Liang
    Nanyang Technological University
    willie, Sep 23, 2005
    #1
    1. Advertising

  2. willie wrote:


    > However, when I use the code below to set the image to correscponding
    > element, it just doesn't show:
    > //code to set gif to image element
    > document.getElementById("spamcode").src = req.responseText;


    Frankly I would forget about XMLHttpRequest and simply do
    document.getElementById("spamcode").src = 'whatever.gif'
    or
    document.getElementById("spamcode").src =
    'serverSideAppGeneratingImage.php'

    There is no need to use XMLHttpRequest to have the browser render some
    image data with an <img> element.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 23, 2005
    #2
    1. Advertising

  3. willie

    willie Guest

    Hi, thanks for your reply, there is a critica that I have to use
    XMLHttpRequest - have to send back the header information I gathered
    previously ( which contains the required cookie info or the server
    simply send back a error page ) together with the image request.

    And also, I am doing this in Apple's Dashboard enviroment, it most
    likely will not store the cookie for me and send it like a browser did,
    I have to store the cookie info in a variable and manuly transfer to
    the server using XMLHttpRequest's header method.

    and this is what I did:
    1. XMLHttpReqest to a index page ->get header which contains certian
    cookie and store it into a variable
    2. make another XMLHttpRequest to another page generating GIF ( require
    cookie info ) -> I send back the cookie info with setRequestHeader
    method
    3. Now I am trying to get the content sent back from the server -> the
    problem occurs.

    That's the most part make me painful...is there any way to parse the
    raw data into gif image?

    regards
    Liao Liang
    Nanyang Technological University
    willie, Sep 24, 2005
    #3
  4. willie wrote:

    > That's the most part make me painful...is there any way to parse the
    > raw data into gif image?


    Mozilla used to support HTML
    <img src="javascript: scriptExpressionReturningImageData">
    respectively script
    imgElement.src = 'javascript: scriptExpressionReturningImageData'
    see
    <http://www.elf.org/colorcube/index.html>
    <http://www.elf.org/pnglets/>

    As you are talking about Apple I guess you want to have that work with
    Safari or the Safari rendering engine, I have no idea whether Safari
    supports that.

    And even if the javascript: pseudo URL src is supported I have doubts
    that you get binary image data into responseText. We head a thread about
    that some while ago, see
    <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/7bdb401f581141d0/94e89601ec14e473?lnk=st&q=responseText+binary+image+data+group:comp.lang.javascript&rnum=1&hl=en#94e89601ec14e473>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 24, 2005
    #4
    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. hb
    Replies:
    6
    Views:
    9,105
  2. Beauregard T. Shagnasty

    Re: filename.gif or filename.gif.jpg?

    Beauregard T. Shagnasty, May 30, 2008, in forum: HTML
    Replies:
    1
    Views:
    733
    Jonathan N. Little
    May 30, 2008
  3. Bergamot
    Replies:
    0
    Views:
    434
    Bergamot
    May 30, 2008
  4. kasper48
    Replies:
    2
    Views:
    96
    Moses
    Oct 21, 2006
  5. fool
    Replies:
    0
    Views:
    105
Loading...

Share This Page