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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.