admin管理员组文章数量:1415119
I send data from a browser to a servlet using JavaScript, then the server processes the data and returns an image as a response (all using xmlhttprequest). I'm sure everything is working fine because when I call the server directly, I get my image back in the browser.
What I was wondering is how, in JavaScript, do I parse my response so that I can display it as an image in an img tag?
I figure this should be fairly easy, but not sure how to do it.
I send data from a browser to a servlet using JavaScript, then the server processes the data and returns an image as a response (all using xmlhttprequest). I'm sure everything is working fine because when I call the server directly, I get my image back in the browser.
What I was wondering is how, in JavaScript, do I parse my response so that I can display it as an image in an img tag?
I figure this should be fairly easy, but not sure how to do it.
Share Improve this question asked Aug 21, 2011 at 23:28 JasonJason 14k15 gold badges79 silver badges129 bronze badges2 Answers
Reset to default 4You could use data URIs and set the base64 encoded binary data as the src
for an image tag.
If you have control over the server, it might be cleaner to have the server give you a URL you can refer to and create a new img
tag with that src
.
Not sure if this would work with your application, but you could use a server-side script to dynamically serve an image, and then just use javascript to change the source of your image.
i.e.
src="image.php?param1=XXXX¶m2=XXXX"
Or just have your XMLHttpRequest
return a new path to an existing image on the server and then just change the src
attribute of your img
.
本文标签: Return image from HTTP Post request in JavascriptStack Overflow
版权声明:本文标题:Return image from HTTP Post request in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745214643a2648090.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论