Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Having problem to get GIF file through XMLHttpRequest

Reply
Thread Tools

Having problem to get GIF file through XMLHttpRequest

 
 
willie
Guest
Posts: n/a
 
      09-23-2005
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%JQDJ(DB"Q"DJ(P@%B"Q" D!J,,(P@J(Q
D! P"DJ(Q@% "Q"D!JPDU;

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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      09-23-2005


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/
 
Reply With Quote
 
 
 
 
willie
Guest
Posts: n/a
 
      09-24-2005
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

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-24-2005


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+imag e+data+group:comp.lang.javascript&rnum=1&hl=en#94e 89601ec14e473>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Freeware to make animated GIF (can Irfanview make an animated GIF?) Annu Pai Digital Photography 4 11-23-2009 12:52 AM
Re: filename.gif or filename.gif.jpg? Bergamot HTML 0 05-30-2008 02:56 PM
Re: filename.gif or filename.gif.jpg? Beauregard T. Shagnasty HTML 1 05-30-2008 01:23 PM
Passing Variables through different functions for an XMLHttpRequest script. kasper48 Javascript 2 10-21-2006 04:43 AM
How to convert a base 64 encoded GIF image to a *.gif file? hb ASP .Net 6 09-28-2004 08:24 PM



Advertisments