jaymc Posted September 21, 2007 Share Posted September 21, 2007 Im using AJAX to replace my current system where an IFRAME is used to display a small set of data such as login time, if they have new messages etc This sits in the corner of my visitors page and refreshes itself every 3 minutes Rather than use an IFRAME I want to place the content in a div and have AJAX fetch the latest information and update the data I have this code which is working, testing purposes its set to 15 seconds function doit() { open_url('ticker.php', 'tick') } 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 + '?ms=' + new Date().getTime(), 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; } window.setTimeout('doit()',15000); } This is working, but its consuming about 0.4MB of memory a second and using 10-20% CPU usage, eventually it consumes around 250MB of memory and crashes the browser Obviously the code is doing something repeatidly that it shouldnt do Just so you know, the first time open_url is called, within the function it initiates window.setTimeout('doit()',15000); which will have it loop an infinate number of times in spaces of 15 seconds Where am I going wrong. Thanks! Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 21, 2007 Author Share Posted September 21, 2007 P.S - While mucking about with the code I had a stack overflow message appear if thats of any use Not getting that with the above code, but maybe its related Definately sounds like an overflow issue with it eating memory until the browser blows up Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 21, 2007 Author Share Posted September 21, 2007 More info.. Ive just added alert('y'); inside the function and Im having that pop up repeatidly so the function is being processed atleast once a second Code is wrong somehow, please advise? 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.