Having problem to get GIF file through XMLHttpRequest

W

willie

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
 
M

Martin Honnen

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.
 
W

willie

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
 
M

Martin Honnen

willie said:
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&rnum=1&hl=en#94e89601ec14e473>
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top