Jump to content

Ajax mysql query every 10 seconds


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">
<script type="text/javascript">

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

xmlhttp.onreadystatechange = function()
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200)

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


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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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