views:

57

answers:

3

I know we can request xml, html as well as text images directly using ajax but can we request files like image, zip etc. using Ajax. How ?

+1  A: 

You could transport the image over an xmlRequest as base64, but since base64 is ~30% larger it will have some impact on your speed.

Snake
A: 

Yes, you can do so. Actually the same ajax principles apply here too. You use a server-side language to download a file.

Sarfraz
+2  A: 

Ajax just means "Making an HTTP request from JavaScript without leaving the page", so yes.

You can't do much that is useful with a zip file or an image if you fetch it with XMLHttpRequest though.

Images can be added to the document by simply generating a new <img> element.

It might help if you provided more information about what you were trying to achieve. It sounds like an xy problem.

David Dorward
Nice XY :). Actually i am stuck in experiment where i have to calculate the time needed for file download. I know its not realistic but this is how it is expected. So i have 2 approaches at first 1. add image(bmp of size 200KB) to DOM and do mathematics on its load event 2. Ajax request to text file (txt 200KB) having text content, on return calculate time. Now i found there is huge difference in time so i thought ajax request and included image in the page might be downloaded differently by browser so i just wanted to try third way i.e. Ajax requeset to fetch image. This is the story.
Anil Namde
Can we calculate time for file download which is done using "Content-Disposition" ? Using javascript on client end ?
Anil Namde