2011-09-28 71 views
1

是否有可能检查内容是否在ajax调用中完全加载,然后显示一些div。直到内容没有完全加载的div不应该显示,内容后,div必须显示使用jQuery?查看ajax调用中的内容

+2

“内容满载”是什么意思?内容是什么?每个Ajax方法都接受一次收到响应后执行的成功回调。 –

+0

@Felix我有图像的内容和图像加载在Ajax。我正在计算div的高度,当完整的内容到来时,我将展示一个div。谢谢 – Harry

回答

1

的答案是基于总的假设,还定义了一个错误回调

$.ajax({ 
    url: "/path/to/server", 
    type: 'POST', 
    data: data, 
    success: function(data){ <-- the success is called upon successful completion  
    //do something with data 
    $("#divID").html(data); 
    $("#divID").show(); <-- assumed the div was hidden initially 
    }, 
    error:function(jxhr){ 
    if(typeof(console)!='undefined'){ 
    console.log(jxhr.status+"--"+jxhr.responseText); 
    } 
} 
}); 
1

使用jQuery ajax call success callback。它只会在完成请求后才会触发:

$.ajax({ 
    type: "GET", 
    url: "some.html", 
    success: function(data){ 
    // show my div here 
    $('#mydivid').html(data).show(); 
    } 
});