{"employees":[
{"firstName":"John","lastName":"Doe" },
{"firstName":"Anna","lastName":"Smith" },
{"firstName":"Peter","lastName":"Jones" }
]
}
var jsonTxt = "";
var request = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
request.open("GET", "data.js", true);
request.onreadystatechange = function()
{
if ((request.readyState == 4) && (request.status == 200))
{
jsonTxt = request.responseText;
var jsonObj = JSON.parse(jsonTxt); // Does NOT work in IE 6 and 7
jLen = jsonObj.employees.length;
var jDiv = document.getElementById("jsonDiv");
jDiv.display = "block";
for (v=0; v<jLen; v++)
{
var contentDiv = document.createElement('DIV');
jDiv.appendChild(contentDiv);
jDiv.innerHTML += "<p style='color:blue;'> First Name: <span>"+jsonObj.employees[v].firstName+
"</span><br> Last Name: <span>"+jsonObj.employees[v].lastName+"</span><br>' </p>";
}
}
}
request.send(null);