dtmjqyfz21793
dtmjqyfz21793
2011-08-19 01:50

AJAX防止图像被反复加载?

So I have a simple AJAX request (not JQuery):

function ajaxfunction(){
var ajaxRequest;
try{
    ajaxRequest = new XMLHttpRequest();
        } catch (e){
    try{
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){
            alert("Your browser sucks"); //error
            return false;
        }
    }
}

ajaxRequest.open("GET", 'pull.php?ms='+new Date().getTime(), true);
ajaxRequest.send(null);  
ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
    var ajaxDisplay = document.getElementById('ajaxDiv');
        ajaxDisplay.innerHTML = ajaxRequest.responseText;
    }
}

}

And I want the request to also pull pictures. Since the request is dynamic (the images shown will change) I do the request over and over. This, however, makes the images flicker. I tried <img src="foobar.jpg" style="visibility:none;" onLoad="this.style.visibility='visible';" /> but that doesn't really help. If anybody knows of any fix, thank you in advance. :D

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • droi5225 droi5225 10年前

    Maybe instead of pulling then entire <img> tag in the ajax response just get the image name and properties to change the targeted image src, height, width, etc... properties to use the new image.

    点赞 评论 复制链接分享
  • douxu3732 douxu3732 10年前

    I wonder if including the image height and width in the style attribute of the img tag would help since it takes a split second for the browser to start downloading the image and get the actual image height and width.

    点赞 评论 复制链接分享

为你推荐