In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how ajax traverses xml documents, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The XMLHttpRequest object provides two properties that can be used to access the server response. The first property, responseText, provides the response as a string, and the second property, responseXML, provides the response as a XML object. Some simple use cases are suitable for getting a response by simple text, such as displaying the response in a warning box, or the response is just a word indicating success or failure
The previous example is to get the server response from the XMLHttpRequest object and use the responseText property of the XMLHttpRequest object to get the response as text.
This time we use the responseXML property of the XMLHttpRequest object to get the result as an XML document. In this way, we can use the W3C DOM method to traverse the XML document. (the previous article more or less talked about DOM, so I won't repeat it here.)
OK, let's look at an example.
First of all, a piece of XML document code (parseXML.xml) is as follows:
ParseXML.xml is as follows:
MinnesotaIowaNorth DakotaTexasOklahomaLouisianaNew YorkNorth CarolinaMassachusettsCaliforniaOregonNevada
MyJsp.jsp is as follows:
My JSP 'MyJsp.jsp' starting page var flg=false;var requestType= "; / / get the XMLHttpRequest object function newXMLHttpRequest () {var xmlreq = false;if (window.XMLHttpRequest) {xmlreq = newXMLHttpRequest ();} else if (window.ActiveXObject) {try {xmlreq = new ActiveXObject (" Msxml2.XMLHTTP ");} catch (E1) {try {xmlreq = new ActiveXObject (" Microsoft.XMLHTTP ");} catch (E2) {}} return xmlreq;} function startRequest (requestedList) {requestType=requestedList;flg=newXMLHttpRequest () / / call the handleStateChange method flg.onreadystatechange = handleStateChange;flg.open ("GET", "parseXML.xml", true); flg.send (null);} / / handle function function handleStateChange () {if (flg.readyState==4) {if (flg.status==200) {if (requestType== "north") {listNorthStates ();} else if (requestType== "all") {listAllStates ();} if (requestType== "south") {listSouthStates () } / / for displaying NorthStates method function listNorthStates () {var xmlDoc=flg.responseXML;var northNode=xmlDoc.getElementsByTagName ("north") [0]; var northStates=northNode.getElementsByTagName ("state"); outputList ("NorthStates", northStates);} / / for displaying SouthStates method function listSouthStates () {var xmlDoc=flg.responseXML;var SouthNode=xmlDoc.getElementsByTagName ("south") [0]; var SouthStates=SouthNode.getElementsByTagName ("state"); outputList ("SouthStates", SouthStates);} / / for displaying AllStates method function listAllStates () {var xmlDoc=flg.responseXML Var allStates=xmlDoc.getElementsByTagName ("state"); outputList ("All States in Document", allStates);} / / output the element and display it in the prompt box function outputList (title,states) {var out=title;var currState=null;for (var iTuno)
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.