AJAX JSON - Javatpoint
AJAX JSON - Javatpoint
Let's see a simple example of getting JSON data using AJAX code.
<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>
Output:
Date:
Time:
https://www.javatpoint.com/ajax-json-example 1/3
3/28/2020 AJAX JSON - javatpoint
Load Information
← prev next →
Build Custom
Runtimes, Faster
Spend less time resolving
dependencies and more time on
ActiveState quality coding.
ANN
Preparation
Company
Interview
Questions
Company
Trending Technologies
https://www.javatpoint.com/ajax-json-example 2/3
3/28/2020 AJAX JSON - javatpoint
B.Tech / MCA
https://www.javatpoint.com/ajax-json-example 3/3