Using AJAX how can I get web server time..

Using AJAX how can I get web server time..

Make an asynchronous call. Here's the HTML with JS.

<html>
<head>
<script language="JavaScript">  
ajax = new XMLHttpRequest();
 
function ShowData()
{  
  ajax.open( "GET", "servertime.php", true );  
  ajax.onreadystatechange = function() 
  {
    if ( ajax.readyState == 4 ) 
    {      
      document.getElementById("DataPanel").innerHTML = ajax.responseText;
    }
  }    
  ajax.send(null);
}  
</script>
 
<title>hey!</title>
</head>
<body>
  <button onclick="ShowData()">Show Data</button>   
  <div id="DataPanel"></div>  
</body>
</html>

Then you'll need a server side page to display the output. Notice how I use servertime.php in the above script. This PHP page will display nothing but the time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.