I am trying to load images through ajax call in jquery using This here. its not working at all and I am not sure what I am doing wrong, I am using firebug and do not see any request. Any help would be appreciated.
var img = $('<img />').attr('src', thumbnailUrl).load(function () {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
alert('broken image!');
} else {
$("#imageHolder").append(img);
}
});
You will want to set the
loadevent handler before setting thesrcso that theloadevent handler will definitively be set before the image actually loads:Here is a demo: http://jsfiddle.net/Y2SWB/
Notice I also added a
.error(function () {...})call rather than handling errors within theloadevent handler.