PDA

View Full Version : Fetch jpeg image via Ajax request and show it in browser - mission impossible?



detra83
16 Jun 2010, 4:23 AM
Hi everyone,

I've been having a nightmare for the past two days. I have written a Delphi ISAPI dll module that is running on IIS server. The module returns JPEG image as a response to GET request. If I go to the module's url, the image is displayed in the browser. I've checked response header and everything is ok.

The problem occurs when I try to send GET request to the same url using Ext.Ajax.Request. Each and every time the failure handler function gets called. I can't figure out what's causing the problem, but no matter what I try, Ajax Request just won't work.

Any help would be greatly appreciated. Also, if I do get the request result back (jpeg image), is there an easy way to display this image in a div somewhere?

Thank you in advance.

=================
Although the request function is dead simple, I'll paste it here anyway:



Ext.lib.Ajax.useDefaultXhrHeader = false;
Ext.Ajax.request(
{
url : 'http://myserver.com/commands/someISAPI.dll',
method: 'GET',
params :{sd:'startDate.value'},
success: function ( result, request )
{
alert(result.responseText, 'Success');
},
failure: function ( result, request )
{
alert(result.responseText, 'Failure');
}
});


As mentioned, the failure function gets called every time. If I paste the url into the browser, the image shows up fine.

Animal
16 Jun 2010, 6:05 AM
Why would you attempt that?

When you could just create an <img> element?

detra83
16 Jun 2010, 9:09 AM
Thanks for the reply Animal. I did use img tag soon after posting here. I was just so focused on getting the Ajax request to work that I didn't even think of any other options.

I eventually ended up adding <img> tag with blank image, then calling this to fetch new image:
document.images['img-id'].src = 'http://myserver.com/commands/someISAPI.dll';

It works perfectly. I can also pass some info to the server like so:
document.images['img-id'].src = 'http://myserver.com/commands/someISAPI.dll?action=' + someActionString;

Just in case someone will stumble on similar problem.

Animal
16 Jun 2010, 9:27 AM
document.images is non-standard.

It would be a Very Good Idea to use W3C standard element access methods.

hrishikeshp19
22 Jun 2011, 9:29 AM
Hello Detra83,

I am looking for something similar, could you post your example here. I want to show an image returned from web service into a panel. Please post whatever you have. Ajax request just doesnt seem to work.

Thanks and best regards,

Hrishikesh P

San Jose State Univ.