XML stands for Extensible Markup Language. It is a markup language defines a set of rules to encoding the document. XML can used to store and transport data and those are self descriptive in nature. XML stores data in plain text format. Extension of XML file is ‘.xml’. Moreover XMLs are similar to HTML, but XML does not have a predefined structure like HTML. Developers can define the structure and tags in XML.
XML language is designed to read both human and machine readable format.
This article shows how can we fetch XML data using AJAX method. The use of XML saves time taken to fetch data from database. Ajax, loads data without refreshing the entire web page. Here shows an example of loading district under each state while changing States. This is done without using a database connection.
step-1 : First create an XML document similar to shown below, name it as dist.XML .
In the XML document, <sample> is the root element and its child elements are <place>. Where <state> and <district> are the subchild of root element.
step-2: After Create an HTML page for view the result. Copy below code and paste it in your editor. Name the html document as load_district.html.
- In district() function,xmlhttp object specifies the type of request and send to dist.xml.
- get the response data as XML data
- loadDistrict() function will filter the XML data based on user requirement.
- nodeValue contains the text and append this nodeValue to district dropdown box.
step-3:Finally execute the code and view the result.