There is some .php file, that returns .png image file.
How to get this image with jQuery $.ajax()
?
Also, is there were some mistakes with input parameters, .php file will return error in JSON way.
How to understand, which infomation was returned - image or JSON with error?
UPDATE:
I need to draw some statistics graphics with this script. .php
file gets some data (for example account id, which statistics is requested) and checks - if this user (user id is got from session is allowed to view the requested user's statistics, or not). If it's allowed than image is returned, if not - than json error.
So i can make but if there will be error, image doesn't load. But I need to show error notification to user.
If you are return this image as attachment to response - I thing you can't get this attachment in javascript variable, otherwise if you return image in a response stream and set property content type you can just assign you .php
to image srs
:
$('img').attr('src', 'my-image-handler.php');
You can use it like this:
<img src="data:image/png;base64,R0lGODlhUA... " width="80" height="15" />
So i suggest you get the base64 encoded string from the ajax request and use that to display the image
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With