In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to achieve AJAX to return XML to the server", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to achieve AJAX to return XML to the server"!
The specific analysis is as follows:
In AJAX, if the XML document is returned on the server side, the XML data can be obtained through the responseXML property of the asynchronous object. And developers can use the relevant methods of DOM to deal with it.
Suppose the XML document returned by the server is as follows:
Member List isaac W13 Jun 24th Cancer 1118159 fresheggs W610 Nov 5th Scorpio 1038818 girlwing W210 Sep 16th Virgo 1307994 tastestory W15 Nov 29th Sagittarius 1095245 lovehate W47 Sep 5th Virgo 6098017 slepox W19 Nov 18th Scorpio 0658635 smartlau W19 Dec 30th Capricorn 0006621 tuonene W210 Nov 26th Sagittarius 0091704 dovecho W19 Dec 9th Sagittarius 1892013 shanghen W42 May 24th Gemini 1544254 venessawj W45 Apr 1st Aries 1523753 lightyear W311 Mar 23th Aries 1002908
The client gets the server-side XML data and displays it in a table. The code is as follows:
ResponseXMLvar xmlHttp;function createXMLHttpRequest () {if (window.ActiveXObject) xmlHttp = new ActiveXObject ("Microsoft.XMLHttp"); else if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest ();} function getXML (addressXML) {var url = addressXML + "? timestamp=" + new Date (); createXMLHttpRequest (); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open ("GET", url); xmlHttp.send (null) } function addTableRow (sName, sClass, sBirth, sConstell, sMobile) {/ / for more information on adding a row in the table, see Section 7.2.1: var oTable = document.getElementById ("member"); var oTr = oTable.insertRow (oTable.rows.length); var aText = new Array (); aText [0] = document.createTextNode (sName); aText [1] = document.createTextNode (sClass); aText [2] = document.createTextNode (sBirth); aText [3] = document.createTextNode (sConstell) AText [4] = document.createTextNode (sMobile); for (var item0)
In other words, the XML data is obtained directly. However, the work of returning XML data in actual development is dynamically generated by the code on the server side (such as ASP.NET, JSP, etc.). In other words, getXML ('...') The file address in 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 XML data on the server side.
The code is as follows:
Demo function getXML (addressXML) {/ / use jquery's ajax method $.ajax ({type: "GET", url:addressXML, dataType: "xml", / / return type (case sensitive) success:function (myXML) {/ / each traverses each tag $(myXML). Find ("member"). Each (function () {var oMember= ", sName=", sClass= ", sBirth=", sConstell= "," sMobile= "" SName = $(this). Find ("name"). Text (); sClass = $(this). Find ("class"). Text (); sBirth = $(this). Find ("birth"). Text (); sConstell = $(this). Find ("constell"). Text (); sMobile = $(this). Find ("mobile"). Text () / / add line $("# member") .append ($("" + sName + "" + sClass + "+ sBirth +"+ sConstell +"+ sMobile +"));})}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.