Jump to content

Ajax mysql query every 10 seconds


Pain

Recommended Posts

Hi there. Im pretty new in AJAX and i've learned some basics from w3schools so i can now confidently load info from the database to the web page without actually reloading it.

 

What i want to learn is how to load info from the database while refreshing it every ten seconds or so.

 

Now i know there are plenty of examples of how to do this, but they all seem different and it really confuses a newbie like me.

 

Here is my basic AJAX script:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Home</title>
<script type="text/javascript">

function loadXML()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
	xmlhttp = new XMLHttpRequest;
}

xmlhttp.onreadystatechange = function()
{
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
	{
		document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
	}
}
xmlhttp.open("GET","users.php",true);
xmlhttp.send();
}


</script>
</head>
<body>
<div id="myDiv">Get the info!</div>
<button type="button" onClick="loadXML()">Greet</button>
</body>
</html>

 

If somebody could guide me all the way... it would be fantastic! I don't want to just copy a line or two but I rather want to understand it. So far i figured that i'd have to use a timer for this matter..?

 

 

Link to comment
https://forums.phpfreaks.com/topic/260302-ajax-mysql-query-every-10-seconds/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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