This example describes how Ajax handles the return of XML to the server. Share to everyone for your reference. The specific analysis is as follows:
In Ajax, if the server side returns an XML document, it can get the XML data from the Responsexml property of the asynchronous object. Developers can use Dom's methods to process it.
Suppose the XML document returned by the server, 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& lt;/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> <mob ile>1307994</mobile> </member> <member> <name>tastestory</name> <class>w15& lt;/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> <clas s>w210</class> <birth>nov 26th</birth> <constell>Sagittarius</constell> < mobile>0091704</mobile> </member> <member> <name>dovecho</name> <class>w19& Lt;/class> <birth>dec 9th</birth&Gt <constell>Sagittarius</constell> <mobile>1892013</mobile> </member> <member> & lt;name>shanghen</name> <class>W42</class> <birth>may 24th</birth> <constell& Gt gemini</constell> <mobile>1544254</mobile> </member> <member> <name>venessawj& lt;/name> <class>W45</class> <birth>apr 1st</birth> <constell>aries</constell&
Gt <mobile>1523753</mobile> </member> <member> <name>lightyear</name> <class& Gt w311</class> <birth>mar 23th</birth> <constell>Aries</constell> <mobile> 1002908</mobile> </member> </list>
The
Client obtains the server-side XML data 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 ">
We can see that the code to get the XML file at the client is as follows:
<input type= "button" value= "Get xml" onclick= "GetXML (' 9-4.xml ');" >
In other words, the XML data is obtained directly. The actual development of the return of XML data work is through the server side (such as: asp.net, JSP, etc.) code generated dynamically. In other words, the file address in GetXML (' ... ') should be the suffix of a dynamic page such as. aspx or. jsp.
Using the jquery framework to implement
If you use the jquery framework on the client side, implement Ajax to get the server-side XML data.
The code is as follows:
The server side does not change the way XML data is delivered.
I hope this article will help you with your AJAX programming.