AJAX JSON Example

Numerous developers use JSON to pass AJAX upgrades between the customer and the server.

Sites upgrading live games scores can be considered as a sample of AJAX. On the off chance that these scores must be upgraded on the site, then they must be put away on the server so that the page can recover the score when it is required.

This is the place we can make utilization of JSON designed information.

	
<html>
<head>
<meta content="text/html; charset=utf-8">
<title>AJAX JSON by Javatpoint</title>
<script type="application/javascript">
function load()
{
   var url = "http://date.jsontest.com/";//use any url that have json data
   var request;

   if(window.XMLHttpRequest){  
    request=new XMLHttpRequest();//for Chrome, mozilla etc
   }  
   else if(window.ActiveXObject){  
    request=new ActiveXObject("Microsoft.XMLHTTP");//for IE only
   }  
   request.onreadystatechange  = function(){
      if (request.readyState == 4  )
      {
        var jsonObj = JSON.parse(request.responseText);//JSON.parse() returns JSON object
        document.getElementById("date").innerHTML =  jsonObj.date;
        document.getElementById("time").innerHTML = jsonObj.time;
      }
   }
   request.open("GET", url, true);
   request.send();
}
</script>
</head>
<body>

Date: <span id="date"></span><br/>
Time: <span id="time"></span><br/>

<button type="button" onclick="load()">Load Information</button>
</body>
</html>