Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AJAX Reload PHP/Div Without Refresh

Posted on 2009-04-05
5
Medium Priority
?
4,694 Views
Last Modified: 2012-05-06
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!
0
Comment
Question by:webseth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24074945
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
 
LVL 5

Expert Comment

by:striker46
ID: 24074958
This post of mine deals on it. Fully functional code included.

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

Regards
0
 
LVL 5

Accepted Solution

by:
striker46 earned 2000 total points
ID: 24074964
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
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24075157
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
 
LVL 1

Author Closing Comment

by:webseth
ID: 31566885
Excellent. Worked perfectly. Ended up going with the "Multiple Div" Tut. Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question