I'm populating the src
attribute of an image dynamically with the following code:
function getLocalUrl(item) {
if (item.item_id != null && item.item_id != "") {
return host + "images/" + item.item_tid + "-" + item.item_id + ".jpg";
} else {
return host + "images/temp/" + item.item_tid + ".jpg";
}
}
...
var cont = "<img class=\"image image-large\" src=\"" + getLocalUrl(item) + "\"/>";
$(element).append(cont);
However when I look at the http requests that my browser makes I see two of them: the first one to
/images/undefined-1.jpg
and the second one to
/images/correctstring-1.jpg
Of course the first one produces an error but the second one downloads the images correctly so the end result is correct. But I still don't understand why the first request is made. The function getLocalUrl is only called once and the item_tid
field is always defined (otherwise the second request wouldn't be produced). I'm a bit of a newbie so I might be missing something very basic.