2012-01-16 43 views
2

我正在使用jquery「.load」functin延遲圖片的「淡入」,直到它們被加載。 但是,它在所有瀏覽器中都能正常工作,只是IE正在製造麻煩 - 它是緩存......到目前爲止,我理解了這個問題......但是如何解決它?有沒有解決這個問題的插件?jQuery的.load函數,在IE中緩存失敗

這裏的代碼示例:

// this is the user thumbnail, which will be loaded from the database, with a random number as filename. 
if (thumb_medium == '1') { 

    // create picture link. 
    var pic = Math.floor(Math.random() * (1000000)); 
    var image_link = "image/image_show.php?id=" + id + "&element=image_profile_thumb_medium" + "&pic=" + pic + '.jpg'; 

    // write the picture link to the src attr. 
    $('#brpr_list_thumb_' + tuple).attr('src', image_link); 
} 
else { 

    // male image - if there is no user picture in the database. 
    if (gender == 'male') { var image_link = "pic/icons/male_128_128.png" }; 

    // female image - if there is no user picture in the database. 
    if (gender == 'female') { var image_link = "pic/icons/female_128_128.png" }; 

    // write the link to the src attr. 
    $('#brpr_list_thumb_' + tuple).attr('src', image_link); 
} 


// when the loading process of the picture is finished a fadeIn happens - this makes problems in IE, but just with the male and female image, which get cached from IE. 
$('#brpr_list_thumb_' + tuple).load(function() { $('#brpr_list_thumb_' + tuple).fadeIn(250) }); 

在這個例子中,男性和女性的形象越來越被IE和他們得到加載他們梅伊不會出現下一次緩存..

是什麼解決它的最好方法是什麼?

回答

0

您可以爲圖像url添加時間戳。試試這個

if (thumb_medium == '1') { 

    // create picture link. 
    var pic = Math.floor(Math.random() * (1000000)); 
    var image_link = "image/image_show.php?id=" + id + "&element=image_profile_thumb_medium" + "&pic=" + pic + '.jpg'; 

    // write the picture link to the src attr. 
    $('#brpr_list_thumb_' + tuple).attr('src', image_link + "&t=" + (new Date()).getTime()); 
} 
else { 

    // male image - if there is no user picture in the database. 
    if (gender == 'male') { var image_link = "pic/icons/male_128_128.png" }; 

    // female image - if there is no user picture in the database. 
    if (gender == 'female') { var image_link = "pic/icons/female_128_128.png" }; 

    // write the link to the src attr. 
    $('#brpr_list_thumb_' + tuple).attr('src', image_link + "?t=" + (new Date()).getTime()); 
} 
+0

那是我thaught太 - 而事實上,我解決這個問題,我從數據庫中加載的圖像這樣......但我怎麼可以添加時間戳此鏈接PIC /圖標/ male_128_128添加一些東西到這個鏈接會導致一個不存在的圖像?!或者我明白這是完全錯誤的 – Andreas 2012-01-16 18:16:09

+0

在我的回答中查看我已經將時間戳添加到您所指的圖像上,並且沒有任何問題,它將正常工作。 – ShankarSangoli 2012-01-16 18:35:02

1

IE超級有用,默認情況下緩存ajax返回值!

如果你想有理智的迴應,你可以手動設置所有你的ajax請求未被緩存。將它放在腳本的頂部:

$.ajaxSetup({ 
    cache: false 
});