index.json
{
"employee" : [
{
"name" : "Suruchi Shukla",
"post" : "Web Devloper",
"department" : "IT"
},
{
"name" : "Abhi Roy",
"post" : "Tech Lead",
"department" : "IT"
}
]
}
index.html
<html>
<head>
<title>JSON Example</title>
</head>
<body>
<script>
//1> Server Connection establishment
var xhttp = new XMLHttpRequest();
//2> Request Service
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//3> Processing request
coonsole.log(xhttp.responseText);
// Typical action to be performed when the document is ready:
var response = JSON.parse(employee);
var employeeAll = response.employee;
var showData = "";
for(var i=0; i<employeeAll.length; i++){
showData += employeeAll[i].name;
}
document.write(showData+"<br/>");
}
};
xhttp.open("GET", "index.json", true);
//4> Finish request Response Connection
xhttp.send();
</script>
</body>
</html>
No comments:
Post a Comment