HTML and CSS Reference
In-Depth Information
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
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.
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).
The JSON.parse method from the json2 library takes a string and turns it into a
JavaScript object.
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.
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.
The < div > tag is given an id called “data”. See Figure 18.25.
Figure 18.24 The JSON string.
Search WWH ::

Custom Search