jve2211 Posted October 6, 2009 Share Posted October 6, 2009 hi. i use this script and every second the browser i open it with uses more memory. is there any way to fix this. function getTijdData() { var xmlhttp = GetXmlHttpObject(); var returnString; xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { returnString = xmlhttp.responseText; tijdDiv.innerHTML = returnString; } } url = "checkTime.php"; xmlhttp.open("POST",url,true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(null); setTimeout('getTijdData()', 1000); } //server script <? $tijd = date("H:i:s"); echo $tijd; ?> Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 6, 2009 Share Posted October 6, 2009 Hi Nothing obvious jumps out at me, although I would be tempted to put the "setTimeout" inside the if(xmlhttp.readyState==4) statement. However can only see this solving your issue if the Ajax call is failing to come back. All the best Keith Quote Link to comment Share on other sites More sharing options...
corbin Posted October 6, 2009 Share Posted October 6, 2009 Actually, if my logic is correct, the setTimeout needs to be moved into the readyState... part. Since it's asynchronous, the function is called, then 1 second later it's called again, then 1 second later it's called again. Regardless of how many pending requests there are. So, if your requests are taking more than 1 second, it will eventually start to have more and more requests each second. Quote Link to comment Share on other sites More sharing options...
jve2211 Posted October 9, 2009 Author Share Posted October 9, 2009 you are right. this all seems quite logical indeed. but it doesnt solve my problem.. my browser just keeps using more and more memory untill i get an out of memory at line... error. i need some way to empty the browsers cash so that it doesnt store the previous time values all the time in the clients system memory.. the website works fine just starts to give broblems afther some time because of this memory issue. so if anyone knows some way to do this. please tell me how Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 9, 2009 Share Posted October 9, 2009 Hi Only other thing I can think to do would be to destroy the xmlhttp object once you have finished with it. This would only do any good if the function that is called onreadystatechange continues to exist after completion and is just builing up and taking more space. Something like this:- function getTijdData() { var xmlhttp = GetXmlHttpObject(); var returnString; xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { returnString = xmlhttp.responseText; document.getElementById('tijdDiv').innerHTML = returnString; setTimeout('getTijdData()', 1000); delete xmlhttp; } } url = "checkTime.php"; xmlhttp.open("POST",url,true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(null); } All the best Keith Quote Link to comment Share on other sites More sharing options...
jve2211 Posted October 17, 2009 Author Share Posted October 17, 2009 thanks but this didnt solve my problem either.. 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.