user441521 user441521 - 1 month ago 5
HTML Question

loading images after page has been loaded

I have a page that uses signalR. The server calls a client function and passes in image paths to it. ie 'Contents/myimage.png'. Inside the client function I use jquery to load these images. I'm not getting any errors in chrome and the images don't have that default didn't load picture in them but the images are also not there. The function is getting called. What am I missing?

client.onStart = function(myPortrait){

<img id="myPortrait" width="256" height="256" />


$.load replaces the html with the content from the url, eg for a function that returns <div>replacement</div>, you would do:


and you'd get

<div id='mydiv'><div>replacement</div></div>

in this case as data is returning the url to the image, you want to set the src of the image, not replace the html, so change to:

client.onStart = function(myPortrait) {
    $("#myPortrait").prop("src", myPortrait);

if you were doing this via an ajax call (rather than a SignalR call):

    url: url,
}).done(function(data) {
    $("#myPortait").prop("src", data);