Berikut adalah contoh penggunaan AJAX dalam mengambil waktu yang ada di server. Aplikasi ini sering digunakan dalam game real time

<title>Ajax Example</title>
<script language=”Javascript”>
function postRequest(strURL) {

var xmlHttp;

if (window.XMLHttpRequest) { // Mozilla, Safari, …
var xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
var xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}‘POST’, strURL, true);


xmlHttp.onreadystatechange = function() {

if (xmlHttp.readyState == 4) {






function updatepage(str){
document.getElementById(“result”).innerHTML =
“<font color=’red’ size=’5′>” + str + “</font>”;;

function showCurrentTime(){
var rnd = Math.random();
var url=”time.php?id=”+rnd;




<h1 align=”center”><font color=”#000080″>Ajax Example</font></h1>
<p><font color=”#000080″>&nbsp;This very simple Ajax Example retrieves the current date and time from server and shows on the form. To view the current date and time click on the following button.</font></p>

<form name=”f1″>

<p align=”center”><font color=”#000080″>&nbsp;<input value=” Show Time”
type=”button” onclick=’JavaScript:showCurrentTime()’

<div id=”result” align=”center”></div>


<div id=result></div>



Dan ini adalah script PHPnya

print date(“l M dS, Y, H:i:s”);