Solved

AJAX Reload PHP/Div Without Refresh

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

12 Experts available now in Live!

Get 1:1 Help Now