Web server generates images and sends them to client directly. There are no URLs to the images, for security reasons. For example, if I enter /images/25 URL in the browser server will send it and browser will download it.
Now I want to get this image from Ajax call and then display it on existing page. I can get the image data. My question is: how can I display an image?
$.get("/images/25", function (rawImageData) {
// ??? Need to add an image to DOM
});
Update
I apologize for being so stupid. Thank you, JW. Of course I can just put img tag with src to my URL. It does not matter if this is a direct URL to an image file or the server sends it dynamically.
So it sounds like there is a URL, and it’s
/images/25.As far as I know, you can’t display image data that you get from an AJAX call*. But why not just put the URL in an
<img>tag? It doesn’t matter to the browser that the image is generated by the server, rather than read from a file.*EDIT: I was wrong; see gideon’s answer if you really need to use an AJAX call (e.g. you need to make a POST request, or send certain headers).