will71110 Posted December 14, 2012 Share Posted December 14, 2012 (edited) So I have this project I'm suppose to be doing. It's to make a web page using AJAX to update a page every 5 seconds, stop/start when a button is pushed, and dynamically update when the back end XML is updated. The problem I have is that it isn't updating (FTP) right after I change the XML. It takes like 5 to 10 mins for it to actually update. here is the code: <script type="text/javascript">var z = 0;var repeatIDfunction halter(url){ if (repeatID){ clearInterval(repeatID) repeatID = null document.getElementById('ChangeMe').innerHTML = "Message paused"; } else{ loadXMLdoc(url) }}function loadXMLdoc(url) { var xmlhttp var txt if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("microsoft.XMLHTTP"); } repeatID = window.setInterval(function() { xmlhttp.open("GET", url, true); xmlhttp.send(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { x = xmlhttp.responseXML.documentElement .getElementsByTagName('message'); if (z < x.length) { xx = x[z].getElementsByTagName("content") txt = xx[0].firstChild.nodeValue z += 1 if (z == x.length){ z = 0 } } } document.getElementById('ChangeMe').innerHTML = txt; } }, 1000);}</script> Is it in my script or is my browser doing something it's not suppose to?? Edited December 14, 2012 by will71110 Link to comment Share on other sites More sharing options...
justsomeguy Posted December 14, 2012 Share Posted December 14, 2012 It might be caching the file. You can append the current timestamp to the end of the XML URL as a querystring parameter to have it always get the current file. Link to comment Share on other sites More sharing options...
will71110 Posted December 17, 2012 Author Share Posted December 17, 2012 Well I figured out that Chrome caches content for around 20 mins. After the 20 mins, my content will update. I'm still new at this so make a link that is time stamped is beyond me currently. Hopefully soon I'll get a better understanding of this and can do like you said justsomeguy. Link to comment Share on other sites More sharing options...
thescientist Posted December 17, 2012 Share Posted December 17, 2012 url += ("t=" + new Date().getTime()) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now