jaymc Posted September 2, 2007 Share Posted September 2, 2007 I am trying to have AJAX fetch the contents of a page and load it into a div Its working fine, however, I need it to do it very 30 seconds which again ive got working fine The problem is, it seems that after 30 seconds, when the page is requested its not actually giving the live contents of that page as the page produces dynamic data Im assuming after the first initial request made by AJAX the page contents are cached therefor if requested again you will get the cached data not the live set Here is the code I have function open_url(url, target) { if (window.ActiveXObject) { link = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { link = new XMLHttpRequest(); } link.onreadystatechange = function() { response(url, target); } link.open("GET", url, true); link.send(null); } function response(url, target) { if (link.readyState == 4) { document.getElementById(target).innerHTML = (link.status == 200) ? link.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the fallowing errorcode: " + link.status; } } Am i right in what im saying, if so is there a way to flush cached data? Feedback would be great! Quote Link to comment Share on other sites More sharing options...
deadimp Posted September 3, 2007 Share Posted September 3, 2007 What kind of file is your request? You can use something (ie. header() in PHP) to tell the browser not to cache the file. Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 3, 2007 Author Share Posted September 3, 2007 Its a php file Its nothing to do with the php file or the header. the ajax is caching the request I tested it using php's microtime(); after the first click it does not update to the current time Its definately caching, any way around it? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted September 19, 2007 Share Posted September 19, 2007 what you have to do is use javascripts random function before every ajax call and supply that as an extra url parameter so that the url is actually different every time. http://www.w3schools.com/jsref/jsref_random.asp function open_url(url, target) { url = url + '&myrand=' + Math.random(); //assuming some other parameters are already being passed Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 21, 2007 Author Share Posted September 21, 2007 Yeh thats the way! Just wondering, when it updates the divs INNERHTML, what happens to its old innerHTML, if its cached in the browser, after x amount of time you could have 5000 X innerHTML divs content wise Is there a way to 'clear the buffer' as it where Quote Link to comment Share on other sites More sharing options...
mainewoods Posted September 21, 2007 Share Posted September 21, 2007 when you do an innerHTML, the old innerHTML contents are overwritten. I could concatenate innerHTML onto whats currently in there like this: element.innerHTML = element.innerHTML + newcontent; //new contents added to the end of my element I'm not aware of any way to clear the buffer. There are headers that can be sent back from the server page(like php) that specify to the browser that no buffering be done. All browsers may not respect that though. If you submit your ajax fields 'POST' instead of 'GET' (assuming you have some actual fields) then the page will usually not be cached even if the data in the submitted fields are identical because browsers don't cache 'POST' submissions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.