0

I am developing my project using backbone.js, underscore.js, require.js and text.js.

I am required to display image that return from c# controller, in my underscore template file. So I did :

<img src=<%=URLBrand+brand[i].ID%> class="brandimg">

In my browser console I got :

<img class="brandimg" src="http://example.com/brand/21">

Error : failed to load given url.

Note : http://example.com/brand/21 is a controller of c# web service return string url of image.

How can I display image return from any url using javascript?

Any answer is appreciated. Thanks.

Nothing
  • 2,644
  • 11
  • 64
  • 115
  • There's already an answer for this question here http://stackoverflow.com/questions/9714525/javascript-image-url-verify – metsawyr Dec 30 '14 at 08:50
  • The type that return from url is actually an image so I don't need to test it. – Nothing Dec 30 '14 at 09:03

2 Answers2

0

As my thinking, you should get the String URL of image first, and then put it in your <img src="put here"/>. You can use ajax for doing this.

  • URL of each image is dynamic and load by underscore.js value and it is not able to write underscore value in javascript function. That's why I couldn't use ajax function here. – Nothing Dec 30 '14 at 09:04
0

You need to get the url string via AJAX-request. And then you can put returned string into src attribute of IMG tag

  Backbone.ajax({
    url: "http://example.com/brand/21",
    success: function(returnedURL){
        //code here
    }
});
nt9142
  • 21
  • 3
  • URL of each image is dynamic and load by `underscore.js` value and it is not able to write `underscore` value in javascript function. That's why I couldn't use ajax function here. – Nothing Dec 30 '14 at 09:02