Home > front end >  I missed what this code? Didn't listen, don't understand, ask big help!
I missed what this code? Didn't listen, don't understand, ask big help!

Time:09-16

"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" & gt;


Sending XML request & lt;/title> <br/><meta name="author" content="Yeeku. H.L ee/& gt;" <br/><meta name="website" content="http://www.crazyit.org"/& gt; <br/><meta HTTP - equiv="content-type" Content="text/HTML. GBK charset="/& gt; <br/></head> <br/><br/><body> <br/><Select the name="first" id="first" onchange="change (this. Value);"> <br/><Option> Please select a country & lt;/option> <br/><The option value="https://bbs.csdn.net/topics/1" selected="selected" & gt; China & lt;/option> <br/><The option value="https://bbs.csdn.net/topics/2" & gt; The United States & lt;/option> <br/><The option value="https://bbs.csdn.net/topics/3" & gt; Japan & lt;/option> <br/></select> <br/><Select id="second" & gt; <br/><Option> Please select a city & lt;/option> <br/></select> <br/><The script type="text/javascript" & gt; <br/>//save the XMLHttpRequest object variable <br/>Var xmlrequest; <br/><br/>The function createXMLHttpRequest () {<br/>If (window. The XMLHttpRequest) {<br/>//browser DOM 2 <br/>Xmlrequest=new XMLHttpRequest (); <br/>} <br/>//IE browser <br/>Else if (window. ActiveXObject) {<br/>Try {<br/>Xmlrequest=new ActiveXObject (" Msxml2. XMLHTTP "); <br/>} the catch (e) {<br/>Try {<br/>Xmlrequest=new ActiveXObject (" Microsoft. XMLHTTP "); <br/>} the catch (e) {} <br/>} <br/>} <br/>} <br/>//event handler, to trigger this function when it is choose to change the present drop-down list <br/>The function change (id) {<br/>//initialize the XMLHttpRequest object <br/>CreateXMLHttpRequest (); <br/>//determine the need to send the URL of the <br/>Var uri="second. JSP"; <br/>//set to POST method to send requests, and open the connection <br/>Xmlrequest. Open (" POST ", uri, true); <br/>//set the request of the POST request header <br/>Xmlrequest. SetRequestHeader (" the content-type ", "application/x - WWW - form - urlencoded"); <br/>//the state change of the XMLHttpRequest object callback function <br/>Xmlrequest. Onreadystatechange=processResponse; <br/>//send the request, sends a request to send the request parameter <br/>Xmlrequest. Send (" id="+ id); <br/>} <br/>//handle the server response <br/>The function processResponse () {<br/>//determine whether the server response complete <br/>If (xmlrequest. ReadyState==4) {<br/>//determine whether the server's response success <br/>If (xmlrequest. Status==200) {<br/>//server for XML response <br/>Var xmldoc=xmlrequest. ResponseXML <br/>//gets the city nodes of the XML document list <br/>Var cityList=xmldoc. GetElementsByTagName (" city "); <br/>//get used to display a drop-down menu drop-down box <br/>Var displaySelect=document. GetElementById (" second "); <br/>//empty list box original options <br/>DisplaySelect. InnerHTML=null; <br/>//in turn traverse multiple city node <br/>for(var i=0; I & lt; CityList. Length; I++) {<br/>//create a option node <br/>Option=document. The createElement method (" option "); <br/>//for the IE browser, text content directly use the text within the DOM node visit <br/>If (cityList [I]. Text) {<br/>Option. The innerHTML=cityList [I]. The text; <br/>} <br/>//for DOM 2 browser, Text content within the DOM node is a Text node <br/>The else {<br/>Option. The innerHTML=cityList [I] firstChild. Data; <br/>} <br/>//in turn will add more than one option to select the <br/>DisplaySelect. The appendChild (option); <br/>} <br/>} <br/>} <br/>} <br/></script> <br/></body> <br/><br/></html><p class="article - content rp"> CodePudding user response: </p>The JSP code <br/><br/><% @ page contentType="text/XML; GBK charset="% & gt; <br/><% <br/>//?????????????????????? <br/>The response. SetContentType (" text/XML; charset=UTF-8"); <br/>Response. SetHeader (" cache-control ", "no - Cache"); <br/>//??? XML????????????? <br/>Out.println (" & lt; Citylist>" ); <br/>Int id=Integer. ParseInt (request. The getParameter (" id ")); <br/>//?????????????????????? XML??? <br/>The switch (id) <br/>{<br/>Case 1: <br/>%> <br/><City> ????? </city> <br/><City> ???? </city> <br/><City> ???? </city> <br/><% <br/>break; <br/>Case 2: <br/>%> <br/><City> ????? </city> <br/><City> ?? </city> <br/><City> ???? </city> <br/><% <br/>break; <br/>Case 3: <br/>%> <br/><City> ???? </city> <br/><City> ???? </city> <br/><City> ???? </city> <br/><% <br/>break; <br/>} <br/>%> <br/></citylist> <br/><p class="article - content rp"> CodePudding user response: </p>Check the encoding format<p class="article - content rp"> CodePudding user response: </p>What a guy, you are a utf-8<p class="article - content rp"> CodePudding user response: </p>File coding had better use utf-8 <br/><p class="article - content rp"> CodePudding user response: </p>I was shocked, yeah you somehow decoding </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/frontend/4227.html" target="_blank" style="color:#999">https//www.codepudding.com/frontend/4227.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/frontend/4226.html'>Give me some bosses look</a></div> <div class="detail-arr-right">Next:<a href='/frontend/4228.html'>Vue package, vendor. Js file not packed into the dist directory</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=JavaScript' target='_blank'>JavaScript</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>