Hi,
The file I have named as time.php and id is 'time'.
Names is the function which is queried from the database Mysql.
When the database record changes I have to change the $time_val in time.php without hitting the refresh key.
The page has to dynamically change when the value gets changed in the database.
Please help me how can I do it using ajax
<?
$name = Names(1);
array_shift($name);
$time_val = $name[0];
?>
<html>
<head>
<script type="text/javascript">function getHTTPObject() {
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest!='undefined'){
try{
xmlhttp = new XMLHttpRequest();
} catch (e){
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject();
function changeDiv(){
var url = "time.php";
http.open("GET", url, true);
http.send(null);
document.getElementById('time').innerHTML = http.responseText;</script>
</head>
<?php
echo '<body onLoad="window.setInterval("changeDiv()",1);">
<div id="time">'.$time_val.'</div>
</body>
</html>';
?>