Jump to content

Update virtual iframe


jaymc

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/70126-update-virtual-iframe/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/70126-update-virtual-iframe/#findComment-352199
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.