久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    <legend id='uKC9Q'><style id='uKC9Q'><dir id='uKC9Q'><q id='uKC9Q'></q></dir></style></legend>
    1. <tfoot id='uKC9Q'></tfoot>

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

    2. 解析 XMLHttpRequest() 結果(使用 XPath)

      Parsing XMLHttpRequest() result (using XPath)(解析 XMLHttpRequest() 結果(使用 XPath))

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

        1. <tfoot id='JQuSV'></tfoot>

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

                <tbody id='JQuSV'></tbody>
                <bdo id='JQuSV'></bdo><ul id='JQuSV'></ul>
              • <legend id='JQuSV'><style id='JQuSV'><dir id='JQuSV'><q id='JQuSV'></q></dir></style></legend>
                本文介紹了解析 XMLHttpRequest() 結果(使用 XPath)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我需要在 JavaScript 中從同一站點加載另一個頁面的可變內容,然后從該內容中獲取數據(解析 XML).

                I need in JavaScript to load in variable contents of another page from the same site and then get data from that contents (parse XML).

                我已經使用 XMLHttpRequest() 和 responseText 屬性在文本字符串變量中獲取了頁面的 HTML.

                I have gotten in text string variable the page's HTML using XMLHttpRequest() and responseText property.

                之后,我將文本字符串轉換為 xml 對象(DOMParser)并嘗試使用 XPath.

                After that I converted text string into xml object (DOMParser) and tried to use XPath.

                在 FireFox 的控制臺中我看到了錯誤:

                In FireFox's console I saw error:

                節點不能在它所在的文檔之外的文檔中使用已創建

                Node cannot be used in a document other than the one in which it was created

                如何將 XMLHttpRequest() 結果轉換為文檔對象以使用 XPath 對其進行處理?我應該如何使用 document.evaluate 和這個對象?有沒有更簡單的方法來完成我的任務?

                How can I convert XMLHttpRequest() result into document object to process it using XPath? How I should use document.evaluate with this object? Is there the easier way to do my task?

                textString=file_get_contents('my url');
                var parser = new DOMParser();
                xml = parser.parseFromString( textString, "text/xml" );
                
                list = getI( "(//td[contains(text(), 'Total:')])[1]",xml);   
                // Error: Node cannot be used in a document other than the one in which it was created`enter code here`     
                // HOW USE getI function here? (document.evaluate)
                
                function file_get_contents( url ) { // Reads entire file into a string
                    // 
                    // +   original by: Legaev Andrey
                    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
                
                    var req = null;
                    try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                        try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
                            try { req = new XMLHttpRequest(); } catch(e) {}
                        }
                    }
                    if (req == null) throw new Error('XMLHttpRequest not supported');
                
                    req.open("GET", url, false);
                    req.send();
                
                    return req.responseText;
                }
                
                function getI(xpath,elem){return document.evaluate(xpath,(!elem?document:elem),null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);}
                

                推薦答案

                在這個任務中有一些時刻:

                There was some moments in this task:

                • 在不使用 req.overrideMimeType 的情況下,屬性 responseXML 已等于 null(在 FireFox 中).在我開始使用 req.overrideMimeType-property responseXML is not null 之后,我仍然無法正確使用 XPath.因此我使用了 responseText 屬性和 DOMParser;
                • 當我們使用 document.evaluate方法我們應該在創建的 HTMLDocument 對象上使用它,而不是用于主文檔對象;
                • 加載時有西里爾字母頁面,所以我應該在 charset windows-1251 中得到結果以正確使用 XPath

                最終結果是:

                req = new XMLHttpRequest();
                req.open("GET", 'http://my_url', false);
                req.overrideMimeType('text/xml; charset=windows-1251'); // for Cyrillic
                req.send(null);
                
                var parser = new DOMParser();
                var xmlDoc = parser.parseFromString(req.responseText, "text/html"); 
                
                var list = xmlDoc.evaluate("(//td[contains(text(), 'Total (Всего):')])[1]",xmlDoc,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
                if(list.snapshotLength>0){
                // operations
                }
                

                這篇關于解析 XMLHttpRequest() 結果(使用 XPath)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)

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

                <legend id='l9WUm'><style id='l9WUm'><dir id='l9WUm'><q id='l9WUm'></q></dir></style></legend>
              • <tfoot id='l9WUm'></tfoot>

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

                          <tbody id='l9WUm'></tbody>
                        • <bdo id='l9WUm'></bdo><ul id='l9WUm'></ul>
                        • 主站蜘蛛池模板: 亚洲日本免费 | 97超碰成人 | 成人免费观看视频 | 手机在线观看av | 色免费视频 | 午夜激情在线视频 | 久久综合久| 日韩欧美精品一区 | 成人精品一区亚洲午夜久久久 | 国产精品一级 | www97影院 | 国产激情在线观看视频 | 不用播放器看的av | 国产一区二区久久 | 一区二区三区国产精品 | 国产精品视频www | 精品国产乱码久久久久久1区2区 | 91原创视频 | 国产中文字幕在线观看 | 亚洲色片网站 | 成人做爰www免费看 午夜精品久久久久久久久久久久 | 国内精品久久久久久影视8 最新黄色在线观看 | 日本成人中文字幕 | 午夜免费视频 | av激情在线 | 成人国产免费观看 | 欧美成人猛片aaaaaaa | 久草99| 日韩欧美手机在线 | 亚洲成av人片在线观看无码 | 最新中文字幕在线播放 | 在线看片国产 | 欧美精品成人影院 | 在线观看视频中文字幕 | 欧美日韩视频在线第一区 | 日韩中文字幕在线观看 | 亚洲乱码国产乱码精品精的特点 | 亚洲精品视频免费看 | 精品久久九 | 国产资源网 | 在线观看亚洲精品视频 |