<i id='vAOj1'><tr id='vAOj1'><dt id='vAOj1'><q id='vAOj1'><span id='vAOj1'><b id='vAOj1'><form id='vAOj1'><ins id='vAOj1'></ins><ul id='vAOj1'></ul><sub id='vAOj1'></sub></form><legend id='vAOj1'></legend><bdo id='vAOj1'><pre id='vAOj1'><center id='vAOj1'></center></pre></bdo></b><th id='vAOj1'></th></span></q></dt></tr></i><div id='vAOj1'><tfoot id='vAOj1'></tfoot><dl id='vAOj1'><fieldset id='vAOj1'></fieldset></dl></div>

        <legend id='vAOj1'><style id='vAOj1'><dir id='vAOj1'><q id='vAOj1'></q></dir></style></legend>

        <small id='vAOj1'></small><noframes id='vAOj1'>

        • <bdo id='vAOj1'></bdo><ul id='vAOj1'></ul>
      1. <tfoot id='vAOj1'></tfoot>

        从 javascript 加载 xml

        时间:2023-10-13
          <bdo id='rXJyA'></bdo><ul id='rXJyA'></ul>
            <tbody id='rXJyA'></tbody>

          <legend id='rXJyA'><style id='rXJyA'><dir id='rXJyA'><q id='rXJyA'></q></dir></style></legend>

          1. <tfoot id='rXJyA'></tfoot>
            <i id='rXJyA'><tr id='rXJyA'><dt id='rXJyA'><q id='rXJyA'><span id='rXJyA'><b id='rXJyA'><form id='rXJyA'><ins id='rXJyA'></ins><ul id='rXJyA'></ul><sub id='rXJyA'></sub></form><legend id='rXJyA'></legend><bdo id='rXJyA'><pre id='rXJyA'><center id='rXJyA'></center></pre></bdo></b><th id='rXJyA'></th></span></q></dt></tr></i><div id='rXJyA'><tfoot id='rXJyA'></tfoot><dl id='rXJyA'><fieldset id='rXJyA'></fieldset></dl></div>

                <small id='rXJyA'></small><noframes id='rXJyA'>

                • 本文介绍了从 javascript 加载 xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  对 XML 完全陌生,我在这个非常简单的目标上苦苦挣扎了太久(尽管我可以在 Internet 上找到足够的信息).只需要这个 xml 文件中的值:

                  Totally new to XML and I've been struggling on this very simple objective for too long (though I can find enough on the internet about it). Just need the values out of this xml file:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <materials>
                      <basic>
                          <uurloon>10</uurloon>
                          <setloon>100</setloon>
                      </basic>
                      <extra>
                          <geluid>150</geluid>
                          <ledset>35</ledset>
                          <strobo>20</strobo>
                          <laser>50</laser>
                      </extra>
                  </materials>
                  

                  在 javascript 中,我使用此代码来获取 xml 数据:

                  In javascript, I use this code to get the xml data:

                  // load xml file
                  if (window.XMLHttpRequest) {
                     xhttp = new XMLHttpRequest();
                  } else {    // IE 5/6
                     xhttp = new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  
                  xhttp.open("GET", "pricing.xml", false);
                  xhttp.send();
                  xmlDoc = xhttp.responseXML; 
                  
                  var uurloon = xmlDoc.getElementsByTagName("uurloon")[0].childNodes[0].text;
                  var setloon = xmlDoc.getElementsByTagName("setloon")[0].childNodes[0].text
                  alert('end');
                  

                  但没有结果,因为我没有看到警报..

                  No result though, cause I'm not seeing the alert..

                  推荐答案

                  您的服务器没有返回适当的 Content-Type 标头.responseXML 属性仅在服务器返回 Content-Type: text/xml 或类似的 +xml 标头时才有效.

                  Your server isn't returning the appropriate Content-Type header. The responseXML property only works if the server returns a Content-Type: text/xml or similar +xml header.

                  查看 Ajax 模式:

                  服务只需要输出一个 XML Content-type header...

                  The service just needs to output an XML Content-type header...

                  来自 w3c:

                  如果最终 MIME 类型不为 null,则 text/xml、application/xml 和不以 +xml 结尾 [...] 返回 null.

                  If final MIME type is not null, text/xml, application/xml, and does not end in +xml [...] return null.

                  如果您无权访问服务器并且无法更改 Content-Type 标头,请使用 overrideMimeType 函数强制 XMLHttpRequest 将响应视为 text/xml:

                  If you have no access to the server and can't change the Content-Type header, use the overrideMimeType function to force the XMLHttpRequest to treat the response as text/xml:

                  if (window.XMLHttpRequest) {
                     xhttp = new XMLHttpRequest();
                  } else {    // IE 5/6
                     xhttp = new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  
                  xhttp.overrideMimeType('text/xml');
                  
                  xhttp.open("GET", "pricing.xml", false);
                  xhttp.send(null);
                  xmlDoc = xhttp.responseXML;
                  
                  var uurloon = xmlDoc.getElementsByTagName("uurloon")[0].childNodes[0].text;
                  var setloon = xmlDoc.getElementsByTagName("setloon")[0].childNodes[0].text
                  alert('end');
                  

                  引用:http://blog-rat.blogspot.com/2010/11/xmlhttprequestresponsexml-returns-null.html

                  这篇关于从 javascript 加载 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:执行用包含脚本标签的 XMLHttpRequest 编写的 Javas 下一篇:当前的 XHR 实现是否利用了 HTTP/2?

                  相关文章

                  最新文章

                  <i id='M3hBZ'><tr id='M3hBZ'><dt id='M3hBZ'><q id='M3hBZ'><span id='M3hBZ'><b id='M3hBZ'><form id='M3hBZ'><ins id='M3hBZ'></ins><ul id='M3hBZ'></ul><sub id='M3hBZ'></sub></form><legend id='M3hBZ'></legend><bdo id='M3hBZ'><pre id='M3hBZ'><center id='M3hBZ'></center></pre></bdo></b><th id='M3hBZ'></th></span></q></dt></tr></i><div id='M3hBZ'><tfoot id='M3hBZ'></tfoot><dl id='M3hBZ'><fieldset id='M3hBZ'></fieldset></dl></div>
                • <legend id='M3hBZ'><style id='M3hBZ'><dir id='M3hBZ'><q id='M3hBZ'></q></dir></style></legend>

                  <small id='M3hBZ'></small><noframes id='M3hBZ'>

                • <tfoot id='M3hBZ'></tfoot>
                    <bdo id='M3hBZ'></bdo><ul id='M3hBZ'></ul>