HTML and CSS Reference
In-Depth Information
EXPLANATION
1 e json2 library provides methods to encode JavaScript objects to JSON, and de-
code the resulting text back to JavaScript objects. The original json2 library doc-
umentation can be found at json.org/js.html.
2
This function is where the server's response is handled and parsed. The XML-
HttpRequest object, called httpRequest in this example, was returned from the
functions not listed but found in Example 18.1.
3
The XMLHttpRequest object's responseText property contains the response from the
server request, a string of text from the “ajaxCar.json” file (see Figure 18.24).
4
The JSON.parse method from the json2 library takes a string and turns it into a
JavaScript object.
5
The special for loop is going through all the properties in the carObject , retrieving
both properties and values to be placed in the div container on line 7.
6
The JSON file will be requested from the server. It has a .json extension. The URL
might be http://localhost/ajaxCar.json , depending on your browser.
7
The < div > tag is given an id called “data”. See Figure 18.25.
Figure 18.24 The JSON string.
Search WWH ::




Custom Search