AJAX Processing Method for XML returned by the server, ajaxxml Processing Method
This article describes how AJAX processes the XML returned by the server. Share it with you for your reference. The specific analysis is as follows:
In AJAX, if the server returns an XML document, you can use the responseXML attribute of the asynchronous object to obtain the XML data of the server. Developers can use DOM-related methods to process them.
Assume that the XML file returned by the server is as follows:
<?xml version="1.0" encoding="gb2312"?><list> <caption>Member List</caption> <member> <name>isaac</name> <class>W13</class> <birth>Jun 24th</birth> <constell>Cancer</constell> <mobile>1118159</mobile> </member> <member> <name>fresheggs</name> <class>W610</class> <birth>Nov 5th</birth> <constell>Scorpio</constell> <mobile>1038818</mobile> </member> <member> <name>girlwing</name> <class>W210</class> <birth>Sep 16th</birth> <constell>Virgo</constell> <mobile>1307994</mobile> </member> <member> <name>tastestory</name> <class>W15</class> <birth>Nov 29th</birth> <constell>Sagittarius</constell> <mobile>1095245</mobile> </member> <member> <name>lovehate</name> <class>W47</class> <birth>Sep 5th</birth> <constell>Virgo</constell> <mobile>6098017</mobile> </member> <member> <name>slepox</name> <class>W19</class> <birth>Nov 18th</birth> <constell>Scorpio</constell> <mobile>0658635</mobile> </member> <member> <name>smartlau</name> <class>W19</class> <birth>Dec 30th</birth> <constell>Capricorn</constell> <mobile>0006621</mobile> </member> <member> <name>tuonene</name> <class>W210</class> <birth>Nov 26th</birth> <constell>Sagittarius</constell> <mobile>0091704</mobile> </member> <member> <name>dovecho</name> <class>W19</class> <birth>Dec 9th</birth> <constell>Sagittarius</constell> <mobile>1892013</mobile> </member> <member> <name>shanghen</name> <class>W42</class> <birth>May 24th</birth> <constell>Gemini</constell> <mobile>1544254</mobile> </member> <member> <name>venessawj</name> <class>W45</class> <birth>Apr 1st</birth> <constell>Aries</constell> <mobile>1523753</mobile> </member> <member> <name>lightyear</name> <class>W311</class> <birth>Mar 23th</birth> <constell>Aries</constell> <mobile>1002908</mobile> </member></list>
The client obtains the XML data from the server and displays it in the table. The Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html>
We can see that the code for obtaining the XML file on the client is as follows:
<Input type = "button" value = "Get XML" onclick = "getXML ('9-4. xml');">
That is to say, XML data is directly obtained. In actual development, XML data is returned dynamically through the code on the server side (such as ASP. NET and JSP. In other words, the file address in getXML ('...') should be the suffix of dynamic pages such as. aspx or. jsp.
Implemented using the jQuery framework
If the jQuery framework is used on the client, AJAX is used to obtain XML data on the server.
The Code is as follows:
<Html>
The method for transferring XML data on the server side remains unchanged.
I hope this article will help you with Ajax programming.