3/28/2020 AJAX JSON - javatpoint
AJAX JSON Example
We can get JSON data by AJAX code. AJAX provides facility to get response asynchronously. It
doesn't reload the page and saves bandwidth.
AJAX JSON Example
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>
Date: <span id="date"></span><br/>
Time: <span id="time"></span><br/>
<button type="button" onclick="load()">Load Information</button>
</body>
</html>
Output:
Date:
Time:
https://www.javatpoint.com/ajax-json-example 1/3
3/28/2020 AJAX JSON - javatpoint
Load Information
← prev next →
Help Others, Please Share
Build Custom
Runtimes, Faster
Spend less time resolving
dependencies and more time on
ActiveState quality coding.
Learn Latest Tutorials
Openpyxl Tally Godot Spring Boot
Tutorial Tutorial Tutorial Tutorial
Openpyxl Tally Godot Spring Boot
Gradle UML Artificial ES6 Tutorial
Tutorial Tutorial Neural
Network ES6
Gradle UML Tutorial
ANN
Flutter Selenium Firebase Cobol
Tutorial Python Tutorial Tutorial
Flutter Selenium Py Firebase Cobol
Preparation
Aptitude Logical Verbal Interview
Reasoning Ability Questions
Aptitude
Reasoning Verbal A. Interview
Company
Interview
Questions
Company
Trending Technologies
https://www.javatpoint.com/ajax-json-example 2/3
3/28/2020 AJAX JSON - javatpoint
Artificial AWS Selenium Cloud
Intelligence Tutorial tutorial tutorial
Tutorial
AWS Selenium Cloud
AI
Hadoop ReactJS Data Science Angular 7
tutorial Tutorial Tutorial Tutorial
Hadoop ReactJS D. Science Angular 7
Blockchain Git Tutorial Machine DevOps
Tutorial Learning Tutorial
Git Tutorial
Blockchain DevOps
ML
B.Tech / MCA
DBMS Data DAA Operating
tutorial Structures tutorial System tutorial
tutorial
DBMS DAA OS
DS
Computer Compiler Computer Discrete
Network Design tutorial Organization Mathematics
tutorial and Tutorial
Compiler D. Architecture
C. Network D. Math.
COA
Ethical Computer Software html tutorial
Hacking Graphics Engineering
Tutorial Tutorial Tutorial Web Tech.
E. Hacking C. Graphics Software E.
Cyber Automata C Language C++ tutorial
Security Tutorial tutorial
tutorial C++
Automata C
Cyber Sec.
Java tutorial .Net Python List of
Framework tutorial Programs
Java tutorial
Python Programs
.Net
Control Data Mining
Systems Tutorial
tutorial
Data Mining
Control S.
https://www.javatpoint.com/ajax-json-example 3/3