这是我的json回复: -
{"Value":[{"Image":"http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/688_dummyadd.jpg","TargetUrl":"http://www.xxxxxxxxxxx.com/xxxxxxx/xxxxxxxxxxs/xxxxxxxxxxxxxxxxxxxxxxx.html","Remark":"Sucess"}]}
这是我的.js代码: -
function showAds(url) {
$.ajax({
url: url,
type : "GET",
dataType : "json",
contentType: "application/json",
async : false,
success : function(msg) {
respo = msg.Value;
$("#adddiv img").remove();
$.each(respo, function(index, value) {
if(value.Image != null) {
image = value.Image;
targetUrl = value.TargetUrl;
$respo = '<img src="'+ image +'" width="266" height="56">';
$('#adddiv').append($respo);
}
});
},
error : function(e) {
console.log(e.message);
alert('Error Occoured');
}
});}
但我无法在屏幕上显示横幅。我该怎么做?我的方法需要改变吗?
答案 0 :(得分:1)
HTML
在adddiv
<img id="id_img" src="'+ image +'" width="266" height="56" src="../img_loading.gif" style="display: none;">
JS中的
.....
....
if(value.Image != null) {
image = value.Image;
var img = new Image();
img.onload = function() {
$("#id_img").show();
$("#id_img").attr("src", image);
}
img.src = image;
}