File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes can server send picture in 'ajax' interaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "can server send picture in Watch "can server send picture in New topic
Author

can server send picture in 'ajax' interaction

Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110
Hello,

Is it possible to send a picture from the web server on an AJAX request. I mean, rather than sending a text/html or a text/xml, can we send an image/gif or something else.

regards,
vijay.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Javascript doesn't know how to handle binary data. You might take a look here and see if this solution fits your needs.


GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Be aware that the example shown on that link makes liberal use of the Prototype and Scriptaculous libraries, which will confuse the #&%$ out of you if you are not familiar with them.

The same effect can be achieved with "straight" JavaScript.

I don't see a need for Ajax at all with regards to loading images.
[ August 07, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by Bear Bibeault:
Be aware that the example shown on that link makes liberal use of the Prototype and Scriptaculous libraries, which will confuse the #&%$ out of you if you are not familiar with them.

The same effect can be achieved with "straight" JavaScript.

I don't see a need for Ajax at all with regards to loading images.

[ August 07, 2006: Message edited by: Bear Bibeault ]


The so called "liberal use" of Prototype and Scriptaculous is this:

Scriptaculous relies on Prototype. That's why prototype is there.
I used one scriptaculous effect on the code shown. That's it. If that's "liberal" then so be it. I used ZERO Ajax, though I think you might have been stating that out of the context of my example.

It's not that #&%$ confusing otherwise, I couldn't use it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Originally posted by Gregg Bolinger:

Scriptaculous relies on Prototype. That's why prototype is there.


Easy there, Hoss!

I was not in any way denigrating your example! Just pointing out that someone who followed the link without having had previous exposure to Prototype might be rather confused -- not by your example, but by the syntax.

I used ZERO Ajax, though I think you might have been stating that out of the context of my example.


Absolutely. That was intended for the OP. I have no idea why he feels that Ajax is necessary to dynamically load images.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Sorry Bear. Having a bit of a day over here. Didn't mean to jump up in arms.

I have no idea why he feels that Ajax is necessary to dynamically load images.

No clue over here either. Maybe he'll clue us in?
Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110
I got the names of all employees in a combo box. On selecting, the employee details is fetched from the database and all this is done using AJAX. I also need to get the image from the database. How do I do that? The image is not stored as a BLOB but is saved as a link.

regards,
vijay.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Originally posted by Vijay Raj:
I got the names of all employees in a combo box.


You must mean a drop-down. There's no such thing as a combo box on the web.


On selecting, the employee details is fetched from the database and all this is done using AJAX. I also need to get the image from the database. How do I do that? The image is not stored as a BLOB but is saved as a link.


I'm not sure what you mean by "saved as a link".

If by that you mean that the file path to the image on disk is what is stored in the database, your Ajax call should return a URL that references that file, and then your page can construc an <img> tag using that URL to cause the image to appear.

You do not return image data to the page, it has no way to deal with it. HTML deals with images via the <img> tag and the use of Ajax or any other technology does not change that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can server send picture in 'ajax' interaction