Solved

AJAX Reload PHP/Div Without Refresh

Posted on 2009-04-05
5
4,663 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
  • 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now