V
V
Voucik2014-01-06 06:56:50
JavaScript
Voucik, 2014-01-06 06:56:50

How to render a resource using js?

js experts, please tell me. How to display an image on a web page, the path to which I receive from the REST FUL service.
More:
There is a WCF Rest Ful service that returns a picture.

[ServiceContract]
public interface IService
    {
        [OperationContract()]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetPic/{value}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        string GetPic(string value);
    }

In {value} I give the id of the picture.
Here is an example (that works) i.e. when I click on this link, I get a code with a picture
voucik.com/Service.svc/GetPic/8EF1ADA2-5865-4DAB-9...
The code is returned as follows:
"<img src="http://voucik.com/Immages/038123ae-f7fe-494b-8f82-1ba06e5d5b4d/8ef1ada2-5865-4dab-949e-4859504fd146/1.png" width=468 height=60 border=0>"

So. The question is, how do I connect all this stuff to the page? So that when the page is launched, this image is displayed.
I tried like this:
<body>
<h2>Show</h2>
<script type="text/javascript" src="http://voucik.com/Service.svc/GetPic/8EF1ADA2-5865-4DAB-949E-4859504FD146">
 </script>
</body>

But that doesn't work, because it's not a resource (file). I think it is necessary to do something like an automatic click on it or something like that.
PS I'm just not very friendly with the web.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timokhin, 2014-01-06
@Voucik

You need to make an AJAX request and put the resulting response on the page.
Example using jQuery:

<script src="http://yandex.st/jquery/2.0.3/jquery.min.js"></script>
<script>
$(function(){
$.get('http://voucik.com/Immages/038123ae-f7fe-494b-8f82-1ba06e5d5b4d/8ef1ada2-5865-4dab-949e-4859504fd146/1.png', {}, function(response){
       $('body').append(response);
});
});
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question