AJAX Reload PHP/Div Without Refresh

I have a page with 2 main divs. I populate these divs using PHP functions with calls to a mySQL database. Here's what I need help with:

My database updates every 4 minutes and I want to "reload" these divs with the new database info every 5 minutes without refreshing the page.

How can I do this? I am a complete AJAX newbie!

Thanks in advance!
LVL 1
websethAsked:
Who is Participating?
 
striker46Connect With a Mentor Commented:
The link I posted above deals on DIV refreshing with AJAX in general, I recommend you read the usage of the code. This other post focuses specifically on refreshing a DIV with MySQL retrieved data using AJAX:

http://www.aleixcortadellas.com/main/?p=320
0
 
Graceful_PenguinCommented:
Just create a timer set on five minutes and then call the php with a normal ajax call then put the response of the ajax call into the innerhtml of the div.
0
 
striker46Commented:
This post of mine deals on it. Fully functional code included.

http://www.aleixcortadellas.com/main/?p=232

Regards
0
 
Graceful_PenguinCommented:
Here is the javascript code to do what you asked. I assume you can do the php part. Also I did not put in all the error handleing but I am sure you can do that.
function TimerTest()
{
	//for other browsers
	req = new XMLHTTPRequest();
	//for ie
	//req = new ActiveXObject("Microsoft.XMLHTTP");
	if (req != null)
	{
		req.open("GET", YourURL , false);
		req.send();
		if (req.responsetext != '')
		{
			divtag = document.getElementById('YOURDIVTAG');	
			divtag.innerHTML = req.responsetext;
		}
		else
			alert('error');
	}
	var t=setTimeout("TimerTest();",1800000);
}

Open in new window

0
 
websethAuthor Commented:
Excellent. Worked perfectly. Ended up going with the "Multiple Div" Tut. Thanks!
0
All Courses

From novice to tech pro — start learning today.