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

      <legend id='cXde1'><style id='cXde1'><dir id='cXde1'><q id='cXde1'></q></dir></style></legend>
      <tfoot id='cXde1'></tfoot>
      • <bdo id='cXde1'></bdo><ul id='cXde1'></ul>

      1. <small id='cXde1'></small><noframes id='cXde1'>

        从 responseText 中获取特定内容

        Get specific content off responseText(从 responseText 中获取特定内容)
        1. <small id='hJTK6'></small><noframes id='hJTK6'>

            • <tfoot id='hJTK6'></tfoot>

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

                  本文介绍了从 responseText 中获取特定内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在进行 ajax 调用,并从 responseText 获取内容.

                  我通过使用 alert 确认,responseText 包含整个页面作为 string.

                  没关系.现在我需要通过将字符串转换为 DOM 并使用 getElementsByTagNamegetElementsByName 等从字符串中提取特定内容...

                  我的问题是这些似乎都不起作用.

                  我已经阅读了很多关于使用 responseXML 而不是 responseText 的参考资料,但这让我返回了 null.

                  那么,坚持responseText,我怎样才能得到我想要的特定元素呢?

                  例如,如果我的回复包含以下内容:

                  <html><head>....</head><身体>..........<桌子><tr><td>一些文本</td><td>其他文本</td></tr><tr><td>一些文本</td><td>其他文本</td></tr><tr><td>一些文本</td><td>其他文本</td></tr></表>

                  somediv </div></身体></html>

                  如何访问表格的第二行及其值?或 div 等.所以,现在在我的实际 html 中,我有这样的东西

                  <html><头>.....</头><身体><table><tr><td id="test">Test</td></tr></table></身体></html>

                  我希望在我的实际 html 的表中解析提取的元素/值..

                  document.getElementById('test').innerHTML = the_extracted_elements_from_responseText

                  解决方案

                  您需要在 html 上使用 DOMParser 并在结果文档上使用 DOM 遍历方法以返回所需的节点.

                   var parser=new DOMParser();var xmlDoc=parser.parseFromString(responseText,"text/xml");var tds = xmlDoc.getElementsByTagName("td");

                  请注意,IE 将需要 new ActiveXObject("Microsoft.XMLDOM");.

                  I am making an ajax call and I get the content from responseText.

                  I confirm by using alert that inside, the responseText contains the entire page as a string.

                  That's fine. Now I need to extract specific contents from the string by converting it to DOM and using getElementsByTagName, getElementsByName etc...

                  My problem is that none of these seems to work.

                  I've read many references on using responseXML instead of responseText but this gives me back null.

                  So, by sticking to responseText, how can i get the specific elements that I want?

                  For instance if my response contains the following:

                  <html>
                  <head>....</head>
                  <body>....
                   .....
                   <table>
                   <tr>
                   <td>sometext</td>
                   <td>someothertext</td>
                   </tr>
                   <tr>
                   <td>sometext</td>
                   <td>someothertext</td>
                   </tr>
                   <tr>
                   <td>sometext</td>
                   <td>someothertext</td>
                   </tr>    
                   </table> 
                   <div> somediv </div>
                   </body>
                   </html>     
                  

                  how can I access the second row of the table and its value? Or the div etc.. so, now in my actual html, i have sth like this

                  <html>
                  <head>.....</head>
                  <body>
                  <table><tr><td id="test">Test</td></tr></table>
                  </body>
                  </html>
                  

                  i want the extracted element/value to be parsed inside the table of my actual html..

                  document.getElementById('test').innerHTML = the_extracted_elements_from_responseText

                  解决方案

                  You need to use a DOMParser on the html and use DOM traversal methods on the resulting document to return the desired node(s).

                    var parser=new DOMParser();
                    var xmlDoc=parser.parseFromString(responseText,"text/xml");
                    var tds = xmlDoc.getElementsByTagName("td");
                  

                  Note that IE would require new ActiveXObject("Microsoft.XMLDOM"); instead.

                  这篇关于从 responseText 中获取特定内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
                  XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
                  Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
                  How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
                  How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
                  quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
                    <tbody id='ilwPy'></tbody>

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

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