Reputation: 639
The situation is that you have to work with an image API and you have to make a POST request to get an image stream that you want to display in the rest of your web page.
I can make an ajax request to that service on page load using jQuery, but i just get a binary stream returned. Is there anyway that JavaScript can take that binary string and display the content type that is in the header?
Upvotes: 5
Views: 18496
Reputation: 117559
I believe what you are looking for is that Data URI Scheme - which allows you to format a really long URI that specifies the needed binary data in itself.
Upvotes: 3
Reputation: 2272
do form post request with targeting an iframe. this is the only way.
Upvotes: 1
Reputation: 5243
Just use javascript to create an img element with the url that returns the image as the src:
// jquery
$(#some-id).append('<img src="/get-image/?foo=bar"/>');
Upvotes: 0
Reputation: 19717
Can you not set an image's src attribute to the url you are using for your ajax communication currently? Or do you have to strip out other info from the ajax call first?
Upvotes: 1
Reputation: 161791
I believe you'll need to arrange to have the stream delivered when a URL is referenced by an HTTP GET operation - then have JavaScript set the src attribute of the image to that URL. I've seen this done with ASP.NET, where a .ashx handler is used to stream the image. One then references http://site.com/images/imagehandler.ashx?parameters.
Upvotes: 2