We can request JSON (
derived from an object
) from the server by using an XMLHttpRequest request
As long as the response from the server is written in JSON format, we can parse the JSON data into a JavaScript object
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
document.getElementById("demo").innerHTML = myObj.name;
}
};
xmlhttp.open("GET", "json_demo.txt", true);
xmlhttp.send();