I've got some AJAX set at an interval to check the server for notifications, etc. Problem is the browser is not caching the images like I thought it would.
Every 2.5 seconds the interval is run and sets the innerHTML of a div from XML, including an image.
The text is fine, but every 2.5 seconds, the image is evidently reloaded, causing the text to shift.
Here is the JS
window.onload = function(){
inth = setInterval(function(){
if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest();}else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){;
try{z=xmlhttp.responseXML.documentElement.getElementsByTagName("activity");}catch (er){z = "";}
for (i=0;i<z.length;i++){
zz=z[i].getElementsByTagName("time");
{try{timez = zz[0].firstChild.nodeValue;}catch (er){timez = "";}}
zz=z[i].getElementsByTagName("str");
{try{ustr = zz[0].firstChild.nodeValue;}catch (er){ustr = "";}}
zz=z[i].getElementsByTagName("user");
{try{user = zz[0].firstChild.nodeValue;}catch (er){user = "";}}
zz=z[i].getElementsByTagName("act");
{try{act = zz[0].firstChild.nodeValue;}catch (er){act = "";}}
ntxt = ntxt + "<div style='border-bottom: 3px dotted #DBDBDB; padding:.5em;'><div><span style='display:inline-block; font-size:14px; font-weight:bold; line-height:14px; margin:0; padding:0;'><img src='avatar.php?size=14&hash="+ustr+"' style='height:14px; display:inline-block;padding:0;margin:0;' /> "+user+"</span></div><span style='font-weight:bold;'>"+act+"</span><small> - "+timez+"</small></div>";
}
ntxt = ntxt + "</div>";
}
document.getElementById('actstream').innerHTML=ntxt;
}
}
xmlhttp.open("GET","ajax_not.php",true);
xmlhttp.send();
}, 2500);
return false;
}
What is the simplest way I can prevent the images from reloading?