Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > AJAX

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 09-28-2009, 02:58 AM
veera veera is offline
Registered User
 
Join Date: Sep 2009
Posts: 1
Arrow Image display using AJAX script

I want to display the image using AJAX script.

Process :
1. I wrote a JSP,Javascript and servlet program and it generates an image.
2. If I click the link text in JSP(HTML data only), it calls the Javascript.
Javascript calls the Servlet, servlet response the image to Javascript.
3. It opened the AJAX window, but the image is not displayed.

I attach the script, if any of you have a solution please share with me.

Thanks,
Veera
ClimbInc, Tokyo.
Attached Files
File Type: zip Ajax.zip (25.2 KB, 35 views)
Reply With Quote
  #2  
Old 09-28-2009, 03:52 PM
Hack's Avatar
Hack Hack is offline
Super Moderator
 
Join Date: Apr 2007
Location: Sterling Heights, Michigan
Posts: 7,719
Welcome to DevX

Does this help?

http://www.xul.fr/ajax/ajax-image-gallery.html
__________________
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista

Microsoft MVP 2005/2006/2007/2008/2009
Reply With Quote
  #3  
Old 10-15-2009, 01:55 AM
jmajews1 jmajews1 is offline
Registered User
 
Join Date: Oct 2009
Posts: 3
Ajax and Binary Data

Based on your use case, I would question why you are using AJAX. Why not open the window to a specified URL and have your Servlet set the response header MIME type to be your image format. The browser will automatically display the image.

If you need to use AJAX then this may be possible by using BASE64 encoding. You can receive the BASE64 encoded image in the AJAX responseText. This technique is documented in the book AJAX - The Complete Reference (McGraw Hill 2008) by Thomas A Powell.

First see http://ajaxref.com/ch4/base64response.html for JavaScript example of BASE64 encoding and how it can be used to decode binary data.

Second see http://tools.ietf.org/html/rfc2397 for information about using the data URI scheme.

Can use image data with XHRs using an addressing schema called a data: URI. A data: URI allows you to include data directly in the address as an immediate form of information ready for consumption without another network fetch. The format of the URI is:

data: [Mime type] [:base64] data

For example, if you used the following data:URI in a browser that can handle the scheme such as Firefox, Opera, or Safari:

data:image/png;base64,[binarydata] where you replace [binarydata] with the encoded image data.

You can use this format to directly embed an image using the <img> tag:

<img src="data:image/png;base64,[binarydata]" ... />

On the server you can set the following headers in the response:
Content-Type: text/plain
Content-Transfer-Encoding: base64

To handle the XHR response you can do something like:

if(xhr.readyState === 4 && xhr.status === 200){
//assume you have the new window reference
//create an img tag with the src equal to the data:URI and
//append it to the new window document body.
var img = document.createElement("img");
var imgsrc = "data:image/png;base64, " + xhr.responseText;
img.setAttribute("src", imgsrc);

//assume window reference is stored in variable called mywin
mywin.document.body.insertBefore(img);
}

Data URI example can be found at http://ajaxref.com/ch4/datauri.html

Note that this technique may not work with Internet Explorer. If you need to support Internet Explorer then I would use the first suggestion above and not use AJAX. If your new window has to display more than just the image you can load the image in an IFRAME.

Hope this helps.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use java script to display an image kumponet Java 5 04-17-2008 02:24 PM
Image display without lossing its resolution. asubash ASP.NET 0 09-28-2007 12:14 PM
Image won't display in Applet syntax_error0 Java 1 02-06-2006 02:33 AM
JavaScript syntax errors for creating new class bubberz ASP.NET 2 08-23-2005 03:19 PM
Script for scrolling Mark Web 3 08-30-2001 12:45 PM


All times are GMT -4. The time now is 02:53 AM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.