AJAX with JSON - Retrieving JSON Text using AJAX
(Page 2 of 4 )
The JSON Text on the web server
In the previous article an equivalent JSON object which has the same structure as the webstudents.xml file was developed using the basic features of the JSON. In particular the following object representing the XML file except for the comment node can also be added if necessary.
var studentAll={"wclass":[
{"student":{"id":"1"},"name":"Linda Jones", "legacySkill":"Access,
VB 5.0"},
{"student":{"id":"2"},"name":"Adam Davidson", "legacySkill":"Cobol,
MainFrame"},
{"student":{"id":"3"},"name":"Charles Boyer", "legacySkill":"HTML, XML"}
]};
The JSONWebStudents.txt file is the textual representation of this serialized object. The JSONWebStudents.txt file is shown in the next listing. This is the file that will be retrieved when the AJAX call is made. Just insert the listing shown in Notepad and save it to the root directory of your server. Notice there is no semi-colon at the end.
Listing of JSONWebStudents.txt:
{"wclass":
[{"student":{"id":"1"},"name":"Linda Jones", "legacySkill":"Access,
VB 5.0"},
{"student":{"id":"2"},"name":"Adam Davidson", "legacySkill":"Cobol,
MainFrame"},
{"student":{"id":"3"},"name":"Charles Boyer", "legacySkill":"HTML,
XML"}]}
Next: The XMLHTTP Request to retrieve JSON >>
More JavaScript Articles
More By Jayaram Krishnaswamy