Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  27] [ 2]  / answers: 1 / hits: 35295  / 12 Years ago, thu, march 1, 2012, 12:00:00

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.


More From » jquery

 Answers
1

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).


[#87123] Wednesday, February 29, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ellisc

Total Points: 533
Total Questions: 82
Total Answers: 90

Location: Bangladesh
Member since Thu, Aug 5, 2021
3 Years ago
;