0

这是我的 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');
        }
    });}

但我无法在屏幕上显示横幅。我该怎么做?我需要改变我的方法吗?

4

1 回答 1

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;           
                          }   
于 2013-09-20T05:34:18.503 回答