views:

717

answers:

2

I have a url that when requested will return an image. I want the url to be requested through an AJAX request. The ajax request returns binary data which is what is being deplayed. but i want the actual image displayed not the binary data. Am using php on the server side and i have set the below headers:

header("Cache-Control: no-cache, must-revalidate");
header ("Content-type: text/jpg; charset=windows-1251");

Please i need advise on what i need to do.

+2  A: 

You need to send an url to this Photo, even if its just a PHP file with an ID

For example

<img src='thumbGenerator.php?id=1337' />

And then this PHP file outputs the binary data.

Ólafur Waage
To be more specific, just use javascript to re-set the src attribute for the image rather than making an AJAX call to your script.
Eric Petroelje
A: 

You need to read up on data urls for binary image data. Keep in mind this method isn't supported in Internet Explorer. If you need cross-browser compatibility then you will need to store the files somewhere on the server and link to them using the images src attribute. Or link the src attribute to a php script that generates the images and serves them correctly.

tj111