2012-12-11 79 views
0

可能重複:
jQuery Ajax wait until all images are loaded延遲AJAX或jQuery的調用,直到動態圖像加載

//var imgURL="http://xxxx.xxx:8084/xxx/largedynamicimagethattakestime 
FB.api(
    '/me/photos', 
    'post', 
    { 
     message:' coffee', 
     url: imgURL   
    }, 
    function(response) { 
     if (!response || response.error) { 
      alert('Error occured'+response.error); 
     } 
     else { 
      //........... 
     } 
    } 
); 

我想推出這個fb.api通話只有當var imgURL完成加載。 有沒有什麼方法可以在div中加載此圖像,並且只有在圖像完全加載後纔打電話給fb.api? 提供帶圖片的按鈕以發佈此圖片也受到歡迎。

回答

1

你要聽的圖像的onload事件:

var image = document.createElement("img"); 
image.onload = function() { 
    // Call API 
}; 

image.src = "http://a57.foxnews.com/global.fncstatic.com/static/managed/img/Scitech/660/371/tardar-sauce-the-cat.jpg"; 

document.body.appendChild(image);