HTML and CSS Reference
In-Depth Information
EXAMPLE 18.21 ( CONTINUED )
httpRequest.setRequestHeader('If-Modified-Since',
'Sat, 03 Jan 2010 00:00:00GMT');
httpRequest.setRequestHeader("Content-type",
"application/json");
httpRequest.send('');
function getXMLContents(httpRequest) {
var httpRequest;
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
textObj=document.getElementById("data");
1
var carObject = eval('('+ httpRequest.responseText
+')') ;
// alert(carObject.make); Using the object's property
2
var details="";
3
for(var property in carObject) {
if (property == "owner"){ // Nested associative
// array
details += "owner name = " +
carObject[property].name + "<br />";
details += "owner cell phone =
" carObject[property].cellphone + "<br />";
}
else{
4
details += property + " = " +
carObject[property] + "<br />";
}
}
5
textObj.innerHTML=details ; // Put data in document
}
// Figure 18.20
else {
alert('There was a problem with the request.');
}
}
}
}
</script>
</head>
<body>
<span style="cursor: pointer; text-decoration: underline"
6
onclick="makeRequest()" >
Get car details
</span>
7
<div id=data>
</div>
</body>
</html>
Search WWH ::




Custom Search