2
The following piece of code aims to place the contents of a text file inside a div. Like the text file can be updated, the div is intended to be updated with the latest file content. But every 2 seconds the contents of the div blinks. How can I achieve the same obtjective without the content of the div blinking? Thank you.
<script type="text/javascript">
setInterval("loadXMLDoc()",2000);
function loadXMLDoc(){
var xmlhttp;
// codigo para IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
document.getElementById("minhaDiv").innerHTML=xmlhttp.responseText;
}
xmlhttp.open("GET","ajax_doc.txt",true);
xmlhttp.send();
}
</script>
Hi John, what you are doing is on the right track. I would change to
setTimeout(loadXMLDoc, 2000);
to be fired inside the.onreadystatechange
to make sure you only get one call at a time. Regarding "blink" gives me the idea that you have a lot of content and that the browser needs time to render... can you change less content at a time? And by the way you can clarify in your question what has this content? Images? text only?– Sergio
It is also necessary to check whether the
responseText
is already available as theonreadystatechange
is called several times before that. Maybe it is the cause of the problem.– bfavaretto
The content is text only. It is a. txt file with only two words. Thank you
– user21958