Tuesday, September 8, 2020

USE OF HTTP REQUEST AND RESPONSE IN JSON

 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=0i<employeeAll.lengthi++){
        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

TODO PROJECT IN REACT JS USING ARRAY HOOK, COMPONENT AND SPREAD OPERATOR

 App.jsx import   React , {  useState  }  from   "react" ; import   TodoList   from   "./TodoList" ; const   App  = ()  ...