Anil Namde
Anil Namde

Reputation: 6608

Is it possible to download image using Ajax

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 ?

Upvotes: 2

Views: 2986

Answers (3)

Quentin
Quentin

Reputation: 943579

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.

Upvotes: 2

Sarfraz
Sarfraz

Reputation: 382706

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

Upvotes: 0

Anemoia
Anemoia

Reputation: 8116

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

Upvotes: 1

Related Questions