Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 加载函数,IE中缓存失败_Jquery_Image_Internet Explorer_Load - Fatal编程技术网

Jquery 加载函数,IE中缓存失败

Jquery 加载函数,IE中缓存失败,jquery,image,internet-explorer,load,Jquery,Image,Internet Explorer,Load,我正在使用jquery“.load”函数延迟图片的“fadeIn”,直到它们被加载。 然而,它在所有浏览器中都运行良好,只是IE制造了麻烦-它是缓存。。。到目前为止我理解了这个问题。。。但如何解决呢?有解决这个问题的插件吗 下面是一个代码示例: // this is the user thumbnail, which will be loaded from the database, with a random number as filename. if (thumb_medium == '1

我正在使用jquery“.load”函数延迟图片的“fadeIn”,直到它们被加载。 然而,它在所有浏览器中都运行良好,只是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缓存,下次加载时,它们不会出现


最好的解决方法是什么?

IE非常有用,默认情况下会缓存ajax返回

如果您希望有合理的响应,您可以手动将所有ajax请求设置为未缓存。将以下内容放在脚本的顶部:

$.ajaxSetup({
  cache: false
});

您可以向图像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()); 
}

这也是我的想法——事实上,我用从数据库加载的图像解决了这个问题。。。但是我怎么能给这个链接添加一个时间戳pic/icons/male_128_128.png给这个链接添加一些东西会导致一个不存在的图像?!或者我理解这个完全错误的观点吗?在我的回答中,我已经将时间戳添加到了您所指的图像中,并且它可以正常工作,没有任何问题。