<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Ajax 核心框架函數及例子

        來源:懂視網 責編:小采 時間:2020-11-27 22:52:30
        文檔

        Ajax 核心框架函數及例子

        Ajax 核心框架函數及例子:核心ajax(options)函數中,包含了建立xmlhttprequest,提取數據,判斷是否回復成功等,基本滿足了日常需求。 代碼如下:// A generic function for performming AJAX requests // It takes one argument, which is a
        推薦度:
        導讀Ajax 核心框架函數及例子:核心ajax(options)函數中,包含了建立xmlhttprequest,提取數據,判斷是否回復成功等,基本滿足了日常需求。 代碼如下:// A generic function for performming AJAX requests // It takes one argument, which is a

        核心ajax(options)函數中,包含了建立xmlhttprequest,提取數據,判斷是否回復成功等,基本滿足了日常需求。
        代碼如下:

        // A generic function for performming AJAX requests
        // It takes one argument, which is an object that contains a set of options
        // All of which are outline in the comments, below
        function ajax( options ) {
        // Load the options object with defaults, if no
        // values were provided by the user
        options = {
        // The type of HTTP Request
        type: options.type || "POST",
        // The URL the request will be made to
        url: options.url || "",
        // How long to wait before considering the request to be a timeout
        timeout: options.timeout || 5000,
        // Functions to call when the request fails, succeeds,
        // or completes (either fail or succeed)
        onComplete: options.onComplete || function(){},
        onError: options.onError || function(){},
        onSuccess: options.onSuccess || function(){},
        // The data type that'll be returned from the server
        // the default is simply to determine what data was returned from the
        // and act accordingly.
        data: options.data || ""
        };
        // Create the request object
        var xml = new XMLHttpRequest();
        // Open the asynchronous POST request
        //xml.open("GET", "/some/url.cgi", true);
        xml.open("GET",options.url, true);
        // We're going to wait for a request for 5 seconds, before giving up
        var timeoutLength = 5000;
        // Keep track of when the request has been succesfully completed
        var requestDone = false;
        // Initalize a callback which will fire 5 seconds from now, cancelling
        // the request (if it has not already occurred).
        setTimeout(function(){
        requestDone = true;
        }, timeoutLength);
        // Watch for when the state of the document gets updated
        xml.onreadystatechange = function(){
        // Wait until the data is fully loaded,
        // and make sure that the request hasn't already timed out
        if ( xml.readyState == 4 && !requestDone ) {
        // Check to see if the request was successful
        if ( httpSuccess( xml ) ) {
        // Execute the success callback with the data returned from the server
        options.onSuccess( httpData( xml, options.type ) );
        // Otherwise, an error occurred, so execute the error callback
        } else {
        options.onError();
        }
        // Call the completion callback
        options.onComplete();
        // Clean up after ourselves, to avoid memory leaks
        xml = null;
        }
        };
        // Establish the connection to the server
        xml.send();
        // Determine the success of the HTTP response
        function httpSuccess(r) {
        try {
        // If no server status is provided, and we're actually
        // requesting a local file, then it was successful
        return !r.status && location.protocol == "file:" ||
        // Any status in the 200 range is good
        ( r.status >= 200 && r.status < 300 ) ||
        // Successful if the document has not been modified
        r.status == 304 ||
        // Safari returns an empty status if the file has not been modified
        navigator.userAgent.indexOf("Safari") >= 0 && typeof r.status == "undefined";
        } catch(e){}
        // If checking the status failed, then assume that the request failed too
        return false;
        }
        // Extract the correct data from the HTTP response
        function httpData(r,type) {
        // Get the content-type header
        var ct = r.getResponseHeader("content-type");
        // If no default type was provided, determine if some
        // form of XML was returned from the server
        var data = !type && ct && ct.indexOf("xml") >= 0;
        // Get the XML Document object if XML was returned from
        // the server, otherwise return the text contents returned by the server
        data = type == "xml" || data ? r.responseXML : r.responseText;
        // If the specified type is "script", execute the returned text
        // response as if it was JavaScript
        if ( type == "script" )
        eval.call( window, data );
        // Return the response data (either an XML Document or a text string)
        return data;
        }
        }

        在同等目錄中,我們可以建立一個rss.xml文件,用這個函數來訪問。
        rss.xml如下:
        代碼如下:

        <titles>
        <title>
        緣份
        </title>
        <title>
        月亮
        </title>
        <title>
        緣份月亮
        </title>
        </titles>

        再建立一個html文檔,調用它,就能看到rss.xml中的內容就能被訪問到。
        整體看看,其實真的比較簡潔和簡單。不僅是能訪問xml格式文件,html,.js格式的文件都可以調用的;
        這些都可以在本地建立對應的文件,進行調用,都可以實現。

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Ajax 核心框架函數及例子

        Ajax 核心框架函數及例子:核心ajax(options)函數中,包含了建立xmlhttprequest,提取數據,判斷是否回復成功等,基本滿足了日常需求。 代碼如下:// A generic function for performming AJAX requests // It takes one argument, which is a
        推薦度:
        標簽: aj 實例 函數
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲国产成人久久综合碰碰动漫3d| 亚洲精品国产V片在线观看| 亚洲av综合色区| 国产成人无码精品久久久久免费| 亚洲高清无码综合性爱视频| 成年网站免费入口在线观看| 亚洲Aⅴ无码一区二区二三区软件 亚洲AⅤ视频一区二区三区 | 免费播放特黄特色毛片| 亚洲AV无码国产剧情| 国产性生交xxxxx免费| 污视频网站在线观看免费| 国产18禁黄网站免费观看| 色老头综合免费视频| 久久亚洲国产精品123区| 99在线免费视频| 亚洲情a成黄在线观看动漫尤物| 免费国产黄网站在线观看视频 | 亚洲综合小说另类图片动图| 成熟女人牲交片免费观看视频| 亚洲熟妇成人精品一区| 午夜亚洲av永久无码精品| 视频免费1区二区三区| 国产AV无码专区亚洲Av| 成年黄网站色大免费全看| 亚洲国产精品日韩av不卡在线| 亚洲第一黄片大全| 鲁丝片一区二区三区免费 | 亚洲网址在线观看你懂的| 永久在线观看www免费视频| 亚洲中文字幕久久精品无码A| 免费在线观看黄网站| 精品在线免费观看| 亚洲avav天堂av在线网爱情| 国产免费啪嗒啪嗒视频看看| a成人毛片免费观看| 亚洲sss综合天堂久久久| 亚洲AV无码一区二区三区在线观看 | 亚洲不卡无码av中文字幕| 麻豆成人久久精品二区三区免费| 亚洲色大成网站www永久网站| 色噜噜亚洲精品中文字幕|